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
#3527 and #3473 together, as one pull request. Both are denial-of-service surfaces from
regular expression backtracking on untrusted input. PolyFile's own HTTP pattern takes about three
minutes on 8 KiB of carriage returns; the Gentoo Manifest pattern takes 3.3 seconds on 306 bytes.
They live in polyfile/http/matcher.py and polyfile/magic_defs/gentoo, so they could be split,
but both want the same timing-bound test helper and duplicating it is worse than one change.
These are the only security-shaped items left, so start here.
Both sub-issues call for "a shared helper that asserts a classification completes within a bound."
One is already in the tree. Verified against master at 906d916.
tests/test_magic.py:
MATCH_TIMEOUT_SECONDS: int = 60 at :556
MATCH_SCRIPT at :558-565, a standalone script that loads MagicMatcher.DEFAULT_INSTANCE,
matches a file, and forces set(match.mimetypes)
MagicMatchingRegressionTest.match_in_subprocess at :627-649 — writes the input to a temp
file, runs MATCH_SCRIPT in a subprocess, fails on subprocess.TimeoutExpired at :645, and
returns elapsed wall-clock seconds
It is not yet a real bound. It only fails when the process exceeds 60 seconds, and it discards
the float it returns — :654 prints the elapsed time and asserts nothing. Neither #3527 nor #3473
would be caught by a 60-second ceiling at the input sizes in their reproducers.
So the shared change this issue exists for is: tighten match_in_subprocess into an actual
assertion, then add one test per sub-issue on top of it. Do not write a second helper.
polyfile/magic_defs/gentoo:38 — the gentoo-manifest named test. Its ten use invocations are at :10, 12, 14, 16, 18 and :24, 26, 28, 30, 32.
One thing to carry into the pull request
polyfile/magic_defs/gentoo is inherited from upstream libmagic (header $File: gentoo,v 1.6 2024/02/11). Patching it makes it the second local patch after c-lang,
and a plain cp file/magic/Magdir/* polyfile/magic_defs/ would silently revert it.
#3479 is building exactly the drift check that makes such patches discoverable, and it is running in
the same wave. Whichever of the two merges second must add the gentoo entry to the other's
allowlist. Note it in the PR body, and add the patch to docs/updating_libmagic_defs.md.
Activity
ESultanik commentedon Sep 11, 2026
A timing helper already exists — reuse it
Both sub-issues call for "a shared helper that asserts a classification completes within a bound."
One is already in the tree. Verified against
masterat906d916.tests/test_magic.py:MATCH_TIMEOUT_SECONDS: int = 60at:556MATCH_SCRIPTat:558-565, a standalone script that loadsMagicMatcher.DEFAULT_INSTANCE,matches a file, and forces
set(match.mimetypes)MagicMatchingRegressionTest.match_in_subprocessat:627-649— writes the input to a tempfile, runs
MATCH_SCRIPTin a subprocess, fails onsubprocess.TimeoutExpiredat:645, andreturns elapsed wall-clock seconds
test_cpp_class_test_terminatesat:651-654, added for Example files that cause an unexpected delay iterating (infinite?) matches #3411It is not yet a real bound. It only fails when the process exceeds 60 seconds, and it discards
the float it returns —
:654prints the elapsed time and asserts nothing. Neither #3527 nor #3473would be caught by a 60-second ceiling at the input sizes in their reproducers.
So the shared change this issue exists for is: tighten
match_in_subprocessinto an actualassertion, then add one test per sub-issue on top of it. Do not write a second helper.
Fix sites
polyfile/http/matcher.py:16— the pattern inside theExactNamedTempfileliteral spanning:16-21. Nothing else in the milestone touches this file.polyfile/magic_defs/gentoo:38— thegentoo-manifestnamed test. Its tenuseinvocations are at:10, 12, 14, 16, 18and:24, 26, 28, 30, 32.One thing to carry into the pull request
polyfile/magic_defs/gentoois inherited from upstream libmagic (header$File: gentoo,v 1.6 2024/02/11). Patching it makes it the second local patch afterc-lang,and a plain
cp file/magic/Magdir/* polyfile/magic_defs/would silently revert it.#3479 is building exactly the drift check that makes such patches discoverable, and it is running in
the same wave. Whichever of the two merges second must add the
gentooentry to the other'sallowlist. Note it in the PR body, and add the patch to
docs/updating_libmagic_defs.md.