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
F15459407: D19847.diff
Mon, Mar 31, 12:41 PM
F15459191: D19847.id.diff
Mon, Mar 31, 10:42 AM
F15399989: D19847.id47404.diff
Mon, Mar 17, 9:00 AM
F15399239: D19847.diff
Mon, Mar 17, 3:29 AM
F15333718: D19847.diff
Sat, Mar 8, 4:15 AM
F15308885: D19847.id47396.diff
Thu, Mar 6, 6:45 AM
F15308884: D19847.id.diff
Thu, Mar 6, 6:45 AM
F15308883: D19847.diff
Thu, Mar 6, 6:45 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