Skip to content

🐛 fix(js): raise MemoryError for lost fold caches - #2544

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:fix/fuzz-self-test
Nov 21, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:fix/fuzz-self-test

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

The fuzz-build self-tests in tests/_html/fuzz/test_self_test.py (-m fuzz_build, run by tox -e fuzz-smoke) have 11 failures on main. They went unnoticed because the scheduled fuzz workflow has stopped at its sanitizer self-check (_fuzz_crash(...) exits without the expected AddressSanitizer report) since 2026-11-16, before pytest starts. The last run that reached these tests, on 2026-11-14 at 552f9af, passed all 150. A local build with the same flags minus the sanitizers (debugoptimized, -Dfuzzing=true, -DTH_OPERATION_LIMIT=100000, PYTHONHASHSEED=0) matches that result at 552f9af and shows the 11 failures on main. Bisecting with it gave these causes:

Tests Cause Fix
8 minify_js allocation sweeps Two allocations added for speed fall back quietly on failure: the analysis jm_compress() hands to the mangler (#2485) and the fold's per-function walk marks (mark_walked()). minify_js() returned its output instead of raising MemoryError, as every other failed allocation in the minifier does. Both mark the program failed (b43a59379).
test_detect_allocation_failure_raises_memory_error #2471 settles a byte order mark without ranking, so detect(b"\xef\xbb\xbftext") makes no allocation for the sweep to fail. Sweep b"caf\xe9 text", which the ranking has to weigh.
test_text_access_allocation_failure_raises_memory_error[text] #2508 builds a lone Text node's .text with PyUnicode_New. That allocates from the object domain, which the PyMem hook does not cover, so there is nothing to fail. The NULL check is in place. Keep only the .data sweep.
test_operation_limit_stops[xpath] #2398 reuses a context-free inner count(//a), so the nested expression finishes far below the limit. Nest counts that depend on their context node: count(//a[count(../a[count(../a) > 0]) > 0]).

With these changes all 164 fuzz_build tests pass on that build, and tox -e 3.15 passes over tests/js and tests/query/xpath. This PR doesn't fix the sanitizer self-check failure in the scheduled workflow.

Two allocations added for speed fell back quietly when they failed: the
analysis the compress pass hands to the mangler (tox-dev#2485) and the fold's
per-function walk marks. minify_js() then returned its output instead of
raising MemoryError, as every other allocation failure in the JavaScript
minifier does, and the allocation-failure sweep in test_self_test.py
caught it. Both now mark the program failed.
Three fuzz-build self-tests stopped testing anything once faster code
paths landed:

- detect() settles a byte order mark without ranking (tox-dev#2471), so the
  BOM input made no allocation for the sweep to fail.
- Text.text of a lone Text node builds its str in place (tox-dev#2508), which
  makes no PyMem allocation the hook can fail; only .data still does.
- tox-dev#2398 reuses a context-free inner count(), so the nested expression
  no longer reached the operation limit.

The detect sweep now feeds input the ranking has to weigh, the text sweep
keeps .data, and the operation-limit expression nests counts that depend
on their context node.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 21, 2026
@codspeed

codspeed Bot commented Nov 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 580 untouched benchmarks
⏩ 91 skipped benchmarks1


Comparing gaborbernat:fix/fuzz-self-test (b0a2536) with main (a58211e)

Open in CodSpeed

Footnotes

  1. 91 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit 2248f64 into tox-dev:main Nov 21, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant