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)
Tue, Feb 4, 3:17 AM
Unknown Object (File)
Fri, Jan 31, 1:46 PM
Unknown Object (File)
Thu, Jan 30, 2:31 PM
Unknown Object (File)
Wed, Jan 29, 11:11 AM
Unknown Object (File)
Fri, Jan 24, 7:22 PM
Unknown Object (File)
Fri, Jan 17, 12:41 PM
Unknown Object (File)
Thu, Jan 16, 10:37 AM
Unknown Object (File)
Dec 31 2024, 11:07 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