startup: check the draw-dump BMP writer's limits and header fields #1710
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1717"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:40:13Z.
Refs #1149.
What the header does
src/startup_stubs/draw_bmp.hwrites the per-draw dumps of the D3D12 stand-in (X2W_DRAW_DUMP_FRAME,src/startup_stubs/d3d12_draw.inl).supported()takes the four 8-bit RGBA/BGRA formats andwrite()turns one copy footprint (rows padded to the footprint'sRowPitch) into a 32-bit bottom-up BMP: it refuses a null file or texel pointer, an unsupported format, a zero width or height, a pitch shorter thanwidth * 4(computed in 64 bits) and an image whose file size does not fit the 32-bitbfSizetogether with the 54 header bytes. It swaps red and blue for RGBA input and writes alpha 255.Tests that reach it
startup_draw_bmp(tests/startup_draw_bmp.cpp) is the only check that includes the header; it is device-free.d3d12_xs_device.cppincludes it for the dumps, but no test runs a dump.Mutation probe
Each mutant was applied alone to
draw_bmp.h,startup_draw_bmp_checkwas rebuilt andctest -R '^startup_draw_bmp$'was run, then the header was restored.width * 4computed in 32 bitsFAIL row size above 4 GiB)stride >= row_pitch(pitch equal to the row size refused)FAIL pitch equal to the row size is accepted)FAIL zero width)FAIL zero height)supported()check droppedbfSizewithout the header bytesbfOffBits= 14biSize= 44biPlanes= 0biBitCount= 24biSizeImage= 0biSizeImage=bfSizebiHeight(top-down)fwriteresult ignoredfwriteresults ignoredExisting check: 10 of 26 killed. With the new cases: 24 of 26 killed.
New cases
BITMAPINFOHEADERfield the writer sets is read:biSize40,biPlanes1,biCompressionBI_RGBandbiSizeImageequal to the image bytes, as well as the fields the check already read.Four mutants are killed by a fault rather than a FAIL line: a writer that accepts those calls goes on to read past the 4-byte buffer or through a null pointer. The unmutated header refuses them before any read.
Negative controls
Registered with
WILL_FAIL TRUE, next tostartup_draw_bmp:startup_draw_bmp_tight_control(--mutate tight): expects a pitch equal to the row size to be refused. PrintsFAIL pitch equal to the row size is accepted.startup_draw_bmp_wrap_control(--mutate wrap): expects the 0x40000001-texel row to be accepted. PrintsFAIL row size above 4 GiB is accepted.startup_draw_bmp_size-image_control(--mutate size-image): expectsbiSizeImage0. Fails the four format cases and the tight case.Not pinned
fwritecalls. Telling them apart from a writer that ignores them needs aFILEthat accepts the 54 header bytes and then fails a row write. A read-only or closed stream fails the header write as well, after which both versions return false.Commands and results
No capability skips. The check uses no device.
Environment
Windows 11 Pro 26300.9974, MSVC from Visual Studio,
devpreset (Debug). Commit5338a26c0c84c38b7d4d5a681dd081dc10fc5510onmainat18a2942a.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:46:56Z.
Review: COMMENTED
Review of head
5338a26c0c84c38b7d4d5a681dd081dc10fc5510. Changes:tests/startup_draw_bmp.cppand test-only CMake entries (astartup_draw_bmp_<mutation>_controlloop withWILL_FAIL); no production code,src/startup_stubs/draw_bmp.huntouched. Verdict: 0 P1, 0 P2.Linux limits. Linux x86_64. Built with
x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -staticand run underwine, not on Windows, not through CTest or CMake.What I ran
startup_draw_bmp: ok, exit 0.--mutate tight,--mutate wrap,--mutate size-imageeach exit 1 with the expectedFAILlines, so the threeWILL_FAILcontrols are meaningful. Unknown mutation names return 2.git diff --check,docs_links_check,bidi_controls_checkclean; no non-ASCII bytes.headers(), which keeps every old condition (type, offset, size, width, height, bit count) and addsbiSize,biPlanes,biCompression,biSizeImage. The old&&chain, which stopped at the first failing format, now runs all four formats. Nothing is weakened.draw_bmp.h(not just the test flags), restored withgit checkout -- .:stride > row_pitch->>=: FAILED (pitch equal to the row size is accepted).std::uint64_t stride->UINT stride: caught, the run faults (exit 5 under wine); the test comment says some mutants fault instead of printing.biSizeImageline removed: FAILED (all four formats andtight headers).MAXDWORD - header_bytes->MAXDWORD: caught by a fault, exit 5.Notes
--mutatecontrols flip the test's own expectation, not the writer, so they show that the assertions are sensitive and rely on theWILL_FAILexit code; the real regression protection is the first list above. A crash also satisfiesWILL_FAIL, which is acceptable here but means a fault in a control would not be told apart from a failed assertion.Not approving (comment only).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:55:44Z.
Review: COMMENTED
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) and Linux at commit
5338a26c0c84c38b7d4d5a681dd081dc10fc5510(0 P1, 0 P2; test-only CMake + test, zero production files changed, zero assertions weakened):git diff --check origin/main...HEAD: PASSpython3 tests/docs_links_check.py: PASS (17 Markdown files, 364 links)python3 tests/bidi_controls_check.py: PASS (1283 tracked files)--preset dev):cmake --build --preset dev --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap startup_draw_bmp_check -- -j 6: PASS (3.59s)ctest --preset dev -R '^(cpu_aot_trap|startup_draw_bmp|startup_draw_bmp_size-image_control|startup_draw_bmp_tight_control|startup_draw_bmp_wrap_control)$' --parallel 4 --no-tests=error --output-on-failure: 5/5 passed (2.01s)/O2(--preset release):cmake --build --preset release --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap startup_draw_bmp_check -- -j 6: PASS (1.72s)ctest --preset release -R '^(cpu_aot_trap|startup_draw_bmp|startup_draw_bmp_size-image_control|startup_draw_bmp_tight_control|startup_draw_bmp_wrap_control)$' --parallel 4 --no-tests=error --output-on-failure: 5/5 passed (1.96s)src/startup_stubs/draw_bmp.hon Win2025 (stride > row_pitch->>=andinfo.biSizeImage = 0):startup_draw_bmpfailed as expected (FAIL R8G8B8A8_UNORM,FAIL B8G8R8A8_UNORM,FAIL R8G8B8A8_UNORM_SRGB,FAIL B8G8R8A8_UNORM_SRGB,FAIL pitch equal to the row size is accepted).AI-assisted; commands listed were executed locally.
upstream-sync referenced this pull request2026-11-24 19:01:30 +00:00