[PR #1601] amd_swizzle: reject impossible sizes, unusable offsets and empty results #1617

Open
opened 2026-11-26 20:21:52 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1601
Author: @xel1uz
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/amd-swizzle-argument-guards


📝 Commits (1)

  • 672dba7 amd_swizzle: reject impossible sizes, unusable offsets and empty results

📊 Changes

2 files changed (+98 additions, -2 deletions)

View changed files

📝 tests/test_amd_swizzle.py (+73 -0)
📝 tools/amd_swizzle.py (+25 -2)

📄 Description

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.py dies with a raw traceback on --width 0 or a negative size, and silently exits 0 with no output when --offset or --modes cannot 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 --out and the blob path, so every other bad argument ended in one of four ways:

  • --width 0 / --height 0 reached Pillow: PIL.UnidentifiedImageError: cannot identify image file.
  • --width -4 reached numpy: ValueError: negative dimensions are not allowed.
  • --offset -1 silently 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.
  • A --modes value matching no pattern table printed nothing and exited 0.
  • The default header path is a Windows-shaped placeholder (<ref>\mesa-addrlib\gfx10SwizzlePattern.h), so on a host without that file the tool died in a raw FileNotFoundError traceback instead of naming AMD_SWIZZLE_HEADER.

Each case now prints one ERROR: line and exits 2 before any work starts, in the same shape as the existing --out guards. 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).
  • The six new cases on the original implementation (patched tool stashed, tests kept): 5 failed, 1 passed - the valid-run test passes on both sides, which is what distinguishes the guards from a workaround.
  • git diff --check clean; python -I scripts/check_no_game_data.py tools/amd_swizzle.py tests/test_amd_swizzle.py exits 0.

GPUs tested: n/a - CPU only, no Vulkan device involved.

AI-assisted: Yes.

Checklist

  • Based on current main (c7e82e26) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption; the tests build a synthetic header and blob.
  • A new translator rule in the contract table of docs/design.md - not applicable, no translator change.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1601 **Author:** [@xel1uz](https://github.com/xel1uz) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/amd-swizzle-argument-guards` --- ### 📝 Commits (1) - [`672dba7`](https://github.com/ubiquitarianism/leonida/commit/672dba76f99afc0439472116c3e5baf5b00ff49d) amd_swizzle: reject impossible sizes, unusable offsets and empty results ### 📊 Changes **2 files changed** (+98 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_amd_swizzle.py` (+73 -0) 📝 `tools/amd_swizzle.py` (+25 -2) </details> ### 📄 Description 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.py` dies with a raw traceback on `--width 0` or a negative size, and silently exits 0 with no output when `--offset` or `--modes` cannot 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 `--out` and the blob path, so every other bad argument ended in one of four ways: - `--width 0` / `--height 0` reached Pillow: `PIL.UnidentifiedImageError: cannot identify image file`. - `--width -4` reached numpy: `ValueError: negative dimensions are not allowed`. - `--offset -1` silently 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. - A `--modes` value matching no pattern table printed nothing and exited 0. - The default header path is a Windows-shaped placeholder (`<ref>\mesa-addrlib\gfx10SwizzlePattern.h`), so on a host without that file the tool died in a raw `FileNotFoundError` traceback instead of naming `AMD_SWIZZLE_HEADER`. Each case now prints one `ERROR:` line and exits 2 before any work starts, in the same shape as the existing `--out` guards. 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). - The six new cases on the original implementation (patched tool stashed, tests kept): 5 failed, 1 passed - the valid-run test passes on both sides, which is what distinguishes the guards from a workaround. - `git diff --check` clean; `python -I scripts/check_no_game_data.py tools/amd_swizzle.py tests/test_amd_swizzle.py` exits 0. GPUs tested: n/a - CPU only, no Vulkan device involved. AI-assisted: Yes. ### Checklist - [x] Based on current `main` (`c7e82e26`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption; the tests build a synthetic header and blob. - [ ] A new translator rule in the contract table of `docs/design.md` - not applicable, no translator change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1617
No description provided.