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
F19082889: D19847.id47404.diff
Dec 2 2025, 12:27 PM
F19081555: D19847.id47396.diff
Dec 2 2025, 7:18 AM
F19059103: D19847.id47404.diff
Nov 29 2025, 4:17 AM
F19032251: D19847.id47396.diff
Nov 25 2025, 5:40 AM
F18984997: D19847.id47396.diff
Nov 17 2025, 12:50 PM
F18902506: D19847.diff
Nov 8 2025, 1:34 AM
F18896455: D19847.id.diff
Nov 7 2025, 4:06 PM
F18887621: D19847.diff
Nov 7 2025, 6:10 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