tinymux/tests/dbt
Stephen Dennis 39ae5062d7 fix(dbt): guard the x64 budget-check backpatch against a full code buffer
The emitters run in dropped-write mode on overflow: emit_byte skips the
store when offset >= capacity but keeps advancing offset, and
translate_block bails post-hoc, discarding the overflowed block.  Every
RAW backpatch -- a direct e->buf[pos] store rather than an emit_* call --
must therefore bounds-check its patch site, because that site can sit
past capacity.

#830 established the rule and guarded emit_patch_rel32.  The a64 emitter
routes its budget-check backpatch through emit_patch_b19, which has
carried the guard from the start.  emit_loop_budget_check (#1571) in the
x64 emitter hand-rolled its short-jump backpatch and missed it -- the one
raw backpatch in the x64 emitter without a guard, shared by the sysv and
win64 backends via dbt_emit_x64.h.

Latent as long as every program switch reset the DBT: the code buffer
stayed far from full, so blocks never overflowed mid-translation.  #2129's
code slots let translations accumulate toward the 4 MB cap, and the bug
became a deterministic SIGSEGV -- 2000 commands round-robin over 32
distinct programs, plain muxscript, faulting on the backpatch store in
dbt_backend_translate_block.  Confirmed causal with the jit_code_slots
knob on one binary: slots=1 completes, slots=7 crashes.

Only x86-64 hosts could crash, and only an x86-64 host could find it:
the guarded-emitter platform (arm64) was the one that could not reach
the bug.

tests/dbt/test_emit_bounds pins the guard with sentinel bytes past a
small capacity -- host-independent, so an arm64 box compiling it still
checks the x64 emitter it cannot execute.  Catch-verified: with the
guard reverted, the two OOB checks go red.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 06:47:42 -06:00
..
.gitignore fix(dbt): guard the x64 budget-check backpatch against a full code buffer 2026-08-06 06:47:42 -06:00
build-msvc.sh build(win32): add /utf-8 to the DBT test build too (#1499) 2026-07-27 05:05:42 -06:00
fuzz_diff.cpp test(dbt): instruction-level differential fuzzer, interpreter vs DBT 2026-07-26 01:11:18 -06:00
Makefile fix(dbt): guard the x64 budget-check backpatch against a full code buffer 2026-08-06 06:47:42 -06:00
test_alarm.cpp fix(tests/dbt): shrink max_dispatch work and stop guessing #1571 (#2101) 2026-08-05 14:37:38 +00:00
test_cache.cpp fix(dbt): overflow-safe guest instruction-fetch bounds (#1864) 2026-07-31 08:59:14 -06:00
test_chain.cpp test(dbt): consolidate the DBT test islands into tests/dbt 2026-07-25 20:41:04 -06:00
test_emit_bounds.cpp fix(dbt): guard the x64 budget-check backpatch against a full code buffer 2026-08-06 06:47:42 -06:00
test_interp.cpp test(dbt): FCVT conformance against qemu-derived golden values 2026-07-25 23:18:03 -06:00
test_reloc.cpp perf(jit): guest code slots — the block cache holds N programs, not 1 (#2129) 2026-08-05 23:14:02 -06:00