Page MenuHomePhabricator

Prevent Pygments from flying off the rails too aggressively
ClosedPublic

Authored by epriestley on Dec 5 2018, 7:15 PM.
Tags
None
Referenced Files
F13222342: D19847.diff
Sun, May 19, 3:31 AM
F13220375: D19847.id47396.diff
Sun, May 19, 1:12 AM
F13204948: D19847.diff
Wed, May 15, 1:16 AM
F13188198: D19847.diff
Sat, May 11, 5:05 AM
F13175471: D19847.diff
Wed, May 8, 5:23 AM
Unknown Object (File)
Tue, May 7, 8:19 AM
Unknown Object (File)
Sun, May 5, 7:04 PM
Unknown Object (File)
Fri, May 3, 8:03 AM
Subscribers
None

Details

Summary

Ref T13224. For some inputs, Pygments has explosive runtime (e.g., 3+ minutes on a 70-character input to the Bash highlighter).

For now, at least limit the maximum amount of damage this can cause. If pygmentize runs for more than 15 seconds, kill it and decline to highlight the file.

In the future, I'd like to take more steps like: fix the Pygments upstream; port more highlighters to PHP; surface this error to the user explicitly.

Test Plan

Tried to highlight echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ as Bash, no more infinite pygmentize.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable