You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gentoo Manifest regex takes superlinear time on runs of whitespace #3473
The gentoo-manifest test in polyfile/magic_defs/gentoo:38 takes superlinear time when the data after the tag is a long run of whitespace. A 306-byte input takes about 4 seconds, and a 506-byte input takes about 28 seconds. The regex window is 8 KiB, so an input a few kilobytes long does not finish.
This is a different root cause from #3411, which is about polyfile/magic_defs/c-lang:78, and it is not fixed by the change in that pull request.
polyfile/magic_defs/gentoo:9-18 invokes the named test gentoo-manifest as soon as an input starts with AUX , DATA , DIST , EBUILD , or MANIFEST . That named test is:
0 name gentoo-manifest
>&0 regex [[:space:]]+[[:print:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:alnum:]]+[[:space:]]+[[:xdigit:]]{32} Gentoo Manifest (GLEP 74)
[[:print:]] and [[:alnum:]] both overlap [[:space:]], and the pattern chains four + quantifiers over overlapping classes. Python's re is a backtracking engine, so the number of ways to split a run of spaces across those quantifiers grows as a polynomial of high degree. Measured against a buffer of only spaces:
Input length
Time
100 bytes
0.05 s
200 bytes
0.73 s
400 bytes
11.2 s
800 bytes
173.5 s
libmagic itself is not affected, because it compiles its tests with a POSIX engine rather than a backtracking one.
The patch in #3546 makes polyfile/magic_defs/gentoo the second local patch to a vendored definition, after c-lang from #3411.
#3547 tracks the underlying cause: PolyFile evaluates regex tests with Python's backtracking re, where libmagic uses a POSIX engine. The definition is not wrong — the engine is, which is why upstream will never change it and this patch has to be carried indefinitely. A scan for the same shape finds 26 candidates across five definition files.
If #3547 lands, this patch and the c-lang one can both be reverted and LOCAL_PATCHES in tests/test_magic_defs_drift.py empties out.
Activity
ESultanik commentedon Sep 11, 2026
The patch in #3546 makes
polyfile/magic_defs/gentoothe second local patch to a vendored definition, afterc-langfrom #3411.#3547 tracks the underlying cause: PolyFile evaluates
regextests with Python's backtrackingre, where libmagic uses a POSIX engine. The definition is not wrong — the engine is, which is why upstream will never change it and this patch has to be carried indefinitely. A scan for the same shape finds 26 candidates across five definition files.If #3547 lands, this patch and the
c-langone can both be reverted andLOCAL_PATCHESintests/test_magic_defs_drift.pyempties out.