Page MenuHomePhabricator

Prevent Pygments from flying off the rails too aggressively
ClosedPublic

Authored by epriestley on Wed, Dec 5, 7:15 PM.

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
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

epriestley created this revision.Wed, Dec 5, 7:15 PM
epriestley requested review of this revision.Wed, Dec 5, 7:15 PM
amckinley accepted this revision.Thu, Dec 6, 12:35 AM
This revision is now accepted and ready to land.Thu, Dec 6, 12:35 AM
This revision was automatically updated to reflect the committed changes.