conformance: the PNG reader rejects an invalid critical chunk structure (OLD-9989) #1331

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

@⁠fin-github on GitHub · 2026-11-24 21:58 UTC · original
fin-github:takeover/old-9989-png-critical-chunks → main · +52 −0 · 2 files · 2 commits · open

Claimed in the coordination issue as: OLD-9989 (#14)

Supersedes draft #259, carried over from old upstream PR 9989 in the original repository. This is the same change cherry-picked onto current main (git cherry-pick -x), with the original author (Tayar) kept on every commit. The change and its explanation are theirs; see #259 for the original description.

Tested

Windows 11 Pro 26200, CPython 3.14.4, on main 4a50cafc7. No GPU, no game files.

  • On this branch: tests/test_conformance_png_transparency.py: 6 tests OK
  • The same test file(s) with main's code: test_invalid_critical_chunk_structure_is_rejected fails in 6 subtests (duplicate IHDR, IEND placement, IDAT order, unknown critical chunk, …), so the tests still catch the bug on current main.
  • scripts/check_no_game_data.py on the changed files and tests/test_text_write_line_endings.py: clean.

GPUs tested: n/a

AI-assisted: yes (Claude Code). The cherry-pick and the test runs were done by the agent; the code is the original author's.

**@⁠fin-github** on GitHub · 2026-11-24 21:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1331) `fin-github:takeover/old-9989-png-critical-chunks` → `main` · +52 −0 · 2 files · 2 commits · open Claimed in the coordination issue as: `OLD-9989` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Supersedes draft #259, carried over from old upstream PR 9989 in the original repository. This is the same change cherry-picked onto current `main` (`git cherry-pick -x`), with the original author (Tayar) kept on every commit. The change and its explanation are theirs; see #259 for the original description. ### Tested Windows 11 Pro 26200, CPython 3.14.4, on `main` 4a50cafc7. No GPU, no game files. - On this branch: `tests/test_conformance_png_transparency.py`: 6 tests OK - The same test file(s) with `main`'s code: `test_invalid_critical_chunk_structure_is_rejected` fails in 6 subtests (duplicate IHDR, IEND placement, IDAT order, unknown critical chunk, …), so the tests still catch the bug on current `main`. - `scripts/check_no_game_data.py` on the changed files and `tests/test_text_write_line_endings.py`: clean. GPUs tested: n/a AI-assisted: yes (Claude Code). The cherry-pick and the test runs were done by the agent; the code is the original author's.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:39 +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 741f4aa5 (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 on crafted PNGs: duplicate IHDR → duplicate IHDR chunk; chunk type 12CD → invalid PNG chunk type ... expected four ASCII letters; non-consecutive IDAT → IDAT chunks must be consecutive; non-empty IEND → IEND must be empty; PLTE after IDAT → invalid PLTE length or position. A valid PNG with split IDATs, PLTE and tEXt still decodes.

Code check: the kind.isalpha() guard is a genuine addition over #1327's first commit — split_png_chunks never validated chunk-type bytes, so non-letter types previously flowed through (only mangled in error messages). For bytes, isalpha() is ASCII-letters-only, matching the PNG spec's A-Z/a-z requirement, and it runs before the critical-chunk check so the decode('ascii') in the duplicate-IHDR message stays safe.

DUPLICATE WARNING: this PR's tree is byte-identical to #1327's head (git diff 741f4aa5 5543594a is empty — same two commits cherry-picked under different hashes: OLD-9989 vs DRAFT-259). Merging both guarantees a same-hunk conflict in read_png plus a duplicate test method; merge one and close the other.

Verdict: verified, correct and slightly broader than #1327's first commit — but only one of the two should land.

AI-assisted verification (Devin).

**@⁠whoalin1** on GitHub · 2026-11-24 23:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1331#issuecomment-7147689772) Independent verification (overnight shift, CPU/tooling only, no game data). Commands run on head 741f4aa5 (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 on crafted PNGs: duplicate IHDR → `duplicate IHDR chunk`; chunk type `12CD` → `invalid PNG chunk type ... expected four ASCII letters`; non-consecutive IDAT → `IDAT chunks must be consecutive`; non-empty IEND → `IEND must be empty`; PLTE after IDAT → `invalid PLTE length or position`. A valid PNG with split IDATs, PLTE and tEXt still decodes. Code check: the `kind.isalpha()` guard is a genuine addition over #1327's first commit — `split_png_chunks` never validated chunk-type bytes, so non-letter types previously flowed through (only mangled in error messages). For `bytes`, `isalpha()` is ASCII-letters-only, matching the PNG spec's A-Z/a-z requirement, and it runs before the critical-chunk check so the `decode('ascii')` in the duplicate-IHDR message stays safe. DUPLICATE WARNING: this PR's tree is byte-identical to #1327's head (`git diff 741f4aa5 5543594a` is empty — same two commits cherry-picked under different hashes: OLD-9989 vs DRAFT-259). Merging both guarantees a same-hunk conflict in `read_png` plus a duplicate test method; merge one and close the other. Verdict: verified, correct and slightly broader than #1327's first commit — but only one of the two should land. 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/1331/head:github-bot/gh-1331'
git switch 'github-bot/gh-1331'

Merge

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