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

Closed
leonida/mandy
fin-github wants to merge 0 commits from takeover/old-9989-png-critical-chunks into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

fin-github commented 2026-11-24 21:58:11 +00:00

Claimed in the coordination issue as: OLD-9989 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145581073)

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.

Claimed in the coordination issue as: `OLD-9989` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145581073) 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.
whoalin1 commented 2026-11-24 23:41:38 +00:00

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).

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).
DadaCap commented 2026-11-28 07:37:44 +00:00

Thanks for this! Closing it as a duplicate of #1327 after a maintainer check that compared the two diffs commit by commit, not just the titles.

This pull request is an exact copy of #1327 (the same diff, line for line), which is older. Keeping #1327 so the fix lands once.

If you think something here is not covered by #1327, say so and we'll reopen it.

AI-assisted (Claude Code), posted for DadaCap (maintainer).

Thanks for this! Closing it as a duplicate of #1327 after a maintainer check that compared the two diffs commit by commit, not just the titles. This pull request is an exact copy of #1327 (the same diff, line for line), which is older. Keeping #1327 so the fix lands once. If you think something here is not covered by #1327, say so and we'll reopen it. _AI-assisted (Claude Code), posted for DadaCap (maintainer)._
Sign in to join this conversation.
No description provided.