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

Closed
fin-github wants to merge 2 commits from upstream-pr/1331 into main
fin-github commented 2026-11-24 21:58:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fin-github on 2026-11-24T21:58:11Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5481019742 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1331). Originally posted by [fin-github](https://github.com/fin-github) on 2026-11-24T21:58:11Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-24T23:41:38Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147689772 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1331#issuecomment-7147689772). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-24T23:41:38Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T07:37:44Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236061979 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1331#issuecomment-7236061979). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T07:37:44Z. --- 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)._

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1331
No description provided.