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
F15539573: D19847.id47404.diff
Fri, Apr 25, 2:40 AM
F15528411: D19847.id47396.diff
Tue, Apr 22, 11:01 AM
F15509732: D19847.id.diff
Wed, Apr 16, 3:33 PM
F15505529: D19847.diff
Tue, Apr 15, 3:53 AM
F15459407: D19847.diff
Mon, Mar 31, 12:41 PM
F15459191: D19847.id.diff
Mon, Mar 31, 10:42 AM
F15399989: D19847.id47404.diff
Mar 17 2025, 9:00 AM
F15399239: D19847.diff
Mar 17 2025, 3:29 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