Skip to content

🐛 fix(fuzz): unbreak the sanitizer smoke gate - #2546

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

gaborbernat merged 6 commits into
tox-dev:mainfrom
gaborbernat:fix/fuzz-self-check

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

The scheduled fuzz workflow has failed every day since 2026-11-15. Its sanitizer self-check runs each _fuzz_crash kind under PYTHONMALLOC=malloc and expects that kind's ASan report. Since #1988, parse() itself reads past the tag-name buffer in the fuzz build, so the first fault kind that parses got a heap-buffer-overflow report instead of its own and the check aborted fuzz-smoke and fuzz-alloc before any test ran. Getting the check past that turned up three more bugs the dead gate had been hiding.

  • th_tag_key loads an 8-byte word of the tag name. The tokenizer counted on the growth policy's 16-byte first allocation, but the fuzz build starts every buffer at two bytes. The tokenizer now reserves the word itself, which leaves release builds at 16 bytes.
  • When the open-element block summaries fail to grow, the pushed element stayed on the stack without a summary slot, and the pop that unwinds the failed parse read past the summary array. The push is now undone on that failure.
  • select_cache_finish formed NULL + 0 (undefined behavior) when the first select cache allocation failed. It now walks the caches by index.
  • url_percent_encode_slow returned NULL without an exception when its buffer allocation failed, so link resolution raised SystemError instead of MemoryError.

A failing self-check now also names the report kind that fired instead, without the stack, which would publish an unfixed bug's location.

Verified in an ubuntu 24.04 container with clang 18 and compiler-rt, the toolchain of the workflow's runner. Combined with #2544, which fixes the 11 test_self_test.py failures the dead gate also hid, tox -e fuzz-smoke passes its self-check and all 164 fuzz-build tests, and tox -e fuzz-alloc sweeps every seed clean under both allocators. The regression coverage is those gates: the self-check, the parse-selectedcontent allocation sweep and the url allocation sweep each fail without the matching fix.

th_tag_key loads a whole 8-byte word of the tag name. The tokenizer's name
buffer relied on the growth policy's 16-byte first allocation for that, but
the fuzz build starts every buffer at two bytes, so every short tag read past
its buffer under ASan. Reserving the word itself keeps release builds at 16
bytes and makes the fuzz build honor the contract.
When the open-element block summaries could not grow, the pushed element
stayed on the stack without a summary slot, and the pop that unwinds the
failed parse read past the summary array. The push is now undone on that
failure. select_cache_finish also formed NULL plus zero when the first select
cache allocation failed; it now walks the caches by index.
url_percent_encode_slow returned NULL without an exception when its output
buffer could not be allocated, so link resolution surfaced SystemError
instead of MemoryError.
A failing sanitizer self-check now says which report kind fired instead, so
an unrelated memory error hiding behind it shows in the log. Only the kind is
printed: the stack would publish an unfixed bug's location.
@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-check (1ea0cce) 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 9087b36 into tox-dev:main Nov 21, 2026
57 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