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
Unknown Object (File)
Thu, Apr 11, 9:36 AM
Unknown Object (File)
Sat, Apr 6, 3:55 PM
Unknown Object (File)
Mar 19 2024, 10:51 PM
Unknown Object (File)
Mar 19 2024, 10:51 PM
Unknown Object (File)
Mar 19 2024, 10:50 PM
Unknown Object (File)
Mar 10 2024, 9:30 PM
Unknown Object (File)
Mar 2 2024, 7:52 AM
Unknown Object (File)
Mar 1 2024, 11:50 PM
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