conformance: validate PNG chunk structure before reading pixels (DRAFT-259) #1327

Open
github-bot wants to merge 2 commits from github-bot/gh-1327 into main AGit
Owner

@⁠fin-github on GitHub · 2026-11-24 21:56 UTC · original
fin-github:codex/draft-259 → main · +52 −0 · 2 files · 2 commits · open

Claimed in the coordination issue as: DRAFT-259 (#14)

What and why

Supersedes carried-over draft #259. Both of Tayar's original commits from old-pr/9989 were cherry-picked with -x onto main at 4a50cafc7.

The comparison tool now rejects invalid PNG chunk layout and chunk types before it uses the pixels. Valid RGB and RGBA images with consecutive IDAT chunks and supported optional chunks still decode.

Tested

On baseline 4a50cafc7, ten synthetic invalid-structure subtests failed because the comparison tool accepted the inputs.

git show 48a5f2bd9:tests/test_conformance_png_transparency.py | python -I -c "exec(compile(__import__('sys').stdin.read(), __file__ := 'tests/test_conformance_png_transparency.py', 'exec'))" -k critical

After the fix, all six PNG tests and all 22 comparison selftest checks passed. Touched-file compilation, changed-file game-data and whitespace checks passed. Both merge simulations were clean.

python -I tests/test_conformance_png_transparency.py
python -I tools/conformance/compare.py selftest
$changed = git diff --name-only upstream/main...HEAD
python -m compileall -q @changed
python -I scripts/check_no_game_data.py @changed
git diff --check upstream/main...HEAD
git merge-tree --write-tree HEAD codex/draft-256
git merge-tree --write-tree HEAD codex/draft-114

Windows 11 build 26200, Python 3.14.4, synthetic inputs only.

GPUs tested: n/a (CPU-only).

AI-assisted (Codex): original patch, rebase and verification.

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
**@⁠fin-github** on GitHub · 2026-11-24 21:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1327) `fin-github:codex/draft-259` → `main` · +52 −0 · 2 files · 2 commits · open Claimed in the coordination issue as: DRAFT-259 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Supersedes carried-over draft #259. Both of Tayar's original commits from `old-pr/9989` were cherry-picked with `-x` onto `main` at `4a50cafc7`. The comparison tool now rejects invalid PNG chunk layout and chunk types before it uses the pixels. Valid RGB and RGBA images with consecutive IDAT chunks and supported optional chunks still decode. ### Tested On baseline `4a50cafc7`, ten synthetic invalid-structure subtests failed because the comparison tool accepted the inputs. ```powershell git show 48a5f2bd9:tests/test_conformance_png_transparency.py | python -I -c "exec(compile(__import__('sys').stdin.read(), __file__ := 'tests/test_conformance_png_transparency.py', 'exec'))" -k critical ``` After the fix, all six PNG tests and all 22 comparison selftest checks passed. Touched-file compilation, changed-file game-data and whitespace checks passed. Both merge simulations were clean. ```powershell python -I tests/test_conformance_png_transparency.py python -I tools/conformance/compare.py selftest $changed = git diff --name-only upstream/main...HEAD python -m compileall -q @changed python -I scripts/check_no_game_data.py @changed git diff --check upstream/main...HEAD git merge-tree --write-tree HEAD codex/draft-256 git merge-tree --write-tree HEAD codex/draft-114 ``` Windows 11 build 26200, Python 3.14.4, synthetic inputs only. GPUs tested: n/a (CPU-only). AI-assisted (Codex): original patch, rebase and verification. ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:33 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 23:41 UTC · original

Independent verification (overnight shift, CPU/tooling only, no game data).

Commands run on head 5543594a (Git Bash, py -3.14):

  • py -3.14 -m compileall -q tools/conformance/compare.py tests/test_conformance_png_transparency.py — clean
  • py -3.14 -I tests/test_conformance_png_transparency.py: Ran 6 tests, OK
  • Manual repro via the module API: crafted PNGs with duplicate IHDR, non-letter chunk type (12CD), non-consecutive IDAT, non-empty IEND, and PLTE after IDAT — each rejected with a specific ToolError naming the violation; valid split-IDAT + PLTE + tEXt file still reads correctly.

Code check: the new loop in read_png enforces PNG spec sections 5.6/11.2 ordering — four-ASCII-letter chunk types, no duplicate IHDR/PLTE, PLTE length 1..768 multiple of 3 and before IDAT, consecutive IDATs, empty IEND. split_png_chunks already verifies length+CRC, so this adds the structural layer on top correctly.

DUPLICATE WARNING: this PR's tree is byte-identical to #1331's head (git diff 5543594a 741f4aa5 is empty — same two commits, different hashes: DRAFT-259 vs OLD-9989). Whichever merges first satisfies both; the other should be closed to avoid a guaranteed same-hunk conflict in read_png and the same test method.

Verdict: verified, correct — but merge only one of #1327/#1331.

AI-assisted verification (Devin).

**@⁠whoalin1** on GitHub · 2026-11-24 23:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1327#issuecomment-7147687020) Independent verification (overnight shift, CPU/tooling only, no game data). Commands run on head 5543594a (Git Bash, py -3.14): - `py -3.14 -m compileall -q tools/conformance/compare.py tests/test_conformance_png_transparency.py` — clean - `py -3.14 -I tests/test_conformance_png_transparency.py`: Ran 6 tests, OK - Manual repro via the module API: crafted PNGs with duplicate IHDR, non-letter chunk type (`12CD`), non-consecutive IDAT, non-empty IEND, and PLTE after IDAT — each rejected with a specific ToolError naming the violation; valid split-IDAT + PLTE + tEXt file still reads correctly. Code check: the new loop in `read_png` enforces PNG spec sections 5.6/11.2 ordering — four-ASCII-letter chunk types, no duplicate IHDR/PLTE, PLTE length 1..768 multiple of 3 and before IDAT, consecutive IDATs, empty IEND. `split_png_chunks` already verifies length+CRC, so this adds the structural layer on top correctly. DUPLICATE WARNING: this PR's tree is byte-identical to #1331's head (`git diff 5543594a 741f4aa5` is empty — same two commits, different hashes: DRAFT-259 vs OLD-9989). Whichever merges first satisfies both; the other should be closed to avoid a guaranteed same-hunk conflict in `read_png` and the same test method. Verdict: verified, correct — but merge only one of #1327/#1331. AI-assisted verification (Devin).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1327/head:github-bot/gh-1327'
git switch 'github-bot/gh-1327'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1327'
git switch 'github-bot/gh-1327'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1327'
git switch 'github-bot/gh-1327'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1327'
git switch 'main'
git merge --squash 'github-bot/gh-1327'
git switch 'main'
git merge --ff-only 'github-bot/gh-1327'
git switch 'main'
git merge 'github-bot/gh-1327'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.