amd_swizzle: reject impossible sizes, unusable offsets and empty results #1601
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1601
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/amd-swizzle-argument-guards"
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?
Pull request successfully merged and closed
Item ID:
AMD-SWIZZLE-ARG-GUARDS(new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here)Claimed as:
AMD-SWIZZLE-ARG-GUARDS-tools/amd_swizzle.pydies with a raw traceback on--width 0or a negative size, and silently exits 0 with no output when--offsetor--modescannot produce an image. Reproduced on c7e82e26 with a synthetic addrlib header and a 256-byte blob.What and why
On c7e82e26 the tool validated only
--outand the blob path, so every other bad argument ended in one of four ways:--width 0/--height 0reached Pillow:PIL.UnidentifiedImageError: cannot identify image file.--width -4reached numpy:ValueError: negative dimensions are not allowed.--offset -1silently sliced the blob from the end;--offset 999(past the end of a 256-byte blob) left an empty buffer. Both exited 0, printed nothing and wrote no image, so a caller could not tell either from a mistyped value.--modesvalue matching no pattern table printed nothing and exited 0.<ref>\mesa-addrlib\gfx10SwizzlePattern.h), so on a host without that file the tool died in a rawFileNotFoundErrortraceback instead of namingAMD_SWIZZLE_HEADER.Each case now prints one
ERROR:line and exits 2 before any work starts, in the same shape as the existing--outguards. A missing or malformed header is reported as such. Valid runs are untouched.Tested
python -m pytest tests/test_amd_swizzle.py -q-> 20 passed, 8 subtests passed (pytest 9.2.0, numpy 2.5.5, Pillow 13.0.0 on Linux).git diff --checkclean;python -I scripts/check_no_game_data.py tools/amd_swizzle.py tests/test_amd_swizzle.pyexits 0.GPUs tested: n/a - CPU only, no Vulkan device involved.
AI-assisted: Yes.
Checklist
main(c7e82e26) and merges cleanly.docs/design.md- not applicable, no translator change.Reviewed 672dba7: ran tests/test_amd_swizzle.py on this branch and on main (your test file copied in): 20/20 pass here; on main the five new guard tests fail and only the valid-run test passes, so they test the fix; the tex_export, tool_startup and resource_hygiene suites pass on both. A CLI probe reproduced all five pre-fix behaviours (negative-dimension and Pillow-on-4x0 tracebacks; silent rc=0 for negative and past-EOF offsets and unmatched --modes); each is now one ERROR line, exit 2. One reproduced residual, non-blocking: a header that parses but references a non-existent NIBBLE row (one NIBBLE01 row, entry
{0, 5, 0, 0, 0}) still raises a raw IndexError traceback, same as on main, because equation() runs outside the new load() guard; a follow-up could validate the indices in load().AI-assisted review.
Recommendation: Merge
Hi @xel1uz, thanks for this pull request.
CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post
claiming: <ID>there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one.The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.
Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough.
AI-assisted (Claude Code, Claude Opus 5.5).
#1601 | head 672dba76f99afc0439472116c3e5baf5b00ff49d (merged cleanly with main c7753ed98a) |
python -m pytest tests/test_amd_swizzle.py -v(tests/requirements.txt: pytest 9.2.0, numpy 2.5.5, Pillow 13.0.0) | red on main:5 failed, 15 passed(--width 0/--height 0/-4,--offset -1,--offset 999, and unmatched--modesexited0instead of2, and missingAMD_SWIZZLE_HEADERraised an unhandledFileNotFoundErrortraceback withrc=1) | green on PR+main:20 passed, 8 subtests passed| Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesAudited
672dba76f9(tools/amd_swizzle.pyandtests/test_amd_swizzle.py) on Windows 11, confirming upfront dimension (>= 1), negative/past-EOF--offset, missing/malformedAMD_SWIZZLE_HEADER(gfx10SwizzlePattern.h), and empty-match--modesguards all exit2with cleanERROR:diagnostics and no traceback. Minor non-blocking note:test_a_valid_run_still_succeedsis gated only by@needs_numpywhile passing--out out.png(which importsPIL.Image), so addingpytest.importorskip("PIL.Image")liketest_cli_previews_uncompressed_r8_and_rg8andtest_preview_keeps_partial_bc_blockswould let partialnumpy-only setups skip cleanly too (fulltests/requirements.txtCI installsPillow==13.0.0and passes 20/20). Also verifiedtests/test_ci_registration.py,tests/test_text_write_line_endings.py, andscripts/check_no_game_data.py.Tested
672dba76fmerged (no commit) withmain829530dbd: Python 3.12.4 with pytest 9.2.0 (fromtests/requirements.txt), Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.python -m pytest tests/test_amd_swizzle.py: 20 passed (8 subtests). Themainversion gives 14 passed.tools/amd_swizzle.pyback tomain, 5 fail: the bad arguments exit 0 instead of 2 (e.g. a negative offset with--width 4 --height 4).No blocker from my side.
AI-assisted (Claude Code).
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14, PR head 672dba76f : red 5 failures / green 20 OK
python -m pytest tests/test_amd_swizzle.py(pytest 9.2.0, venv):FileNotFoundError, instead of 2):test_rejects_non_positive_dimensionstest_rejects_negative_offsettest_rejects_offset_past_the_endtest_reports_when_no_pattern_matchestest_reports_a_missing_or_malformed_headergit merge --no-ffof this PR): 20 passed, 8 subtests passed.git merge-tree).Same result as TheGeogeo's Windows verification.
Verdict: READY
AI-assisted: Claude Code
Tested
672dba76fmerged (no commit) withmain7c330c76d: Python 3.12.4, Windows 11 10.0.26300, CPU only.pytest tests/test_amd_swizzle.pygives 20 passed (8 subtests).tools/amd_swizzle.pyback tomain, 5 fail:test_rejects_non_positive_dimensions,test_rejects_negative_offset,test_rejects_offset_past_the_end,test_reports_when_no_pattern_matchesandtest_reports_a_missing_or_malformed_header.main's own version gives 14 passed.check_no_game_data.pyis clean.AI-assisted (Claude Code).
Merging. Head
672dba76fhas red/green verdicts from reviewers other than the author (above), merges cleanly withmain7c330c76d, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (translator-testsmesh,semantic-testsf16) are pre-existing. Merged by MoonEyes.AI-assisted (Claude Code).