gallery: serve PNG thumbnails for textures saved as upper.DDS #2105

Closed
Tyrannys wants to merge 4 commits from upstream-pr/2105 into main
Tyrannys commented 2026-11-25 20:50:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-25T20:50:46Z.


Claimed in the coordination issue as: GALLERY-THUMB-UPPERCASE-DDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7174150654)

What and why

From CrazyThiago's finding in the coordination issue: tools/gallery.py answers /textures/<stem>.png with a PNG made from <stem>.dds when no PNG exists, but it only tried the lowercase .dds name. On a case-sensitive filesystem a texture saved as upper.DDS is not upper.dds, so the catalog listed it and its thumbnail was a 404.

When <stem>.dds is not a file, the handler now looks in the same folder for a file whose name matches it in any case (dds_sibling). The candidate is the path safe_subpath already resolved inside the textures folder, and the sibling is in that same folder, so the containment guarantee is unchanged. A name that matches nothing in any case is still a 404.

The regression test makes os.path.isfile case-sensitive and stops os.path.realpath from correcting the name's case. On Windows realpath returns the real case (upper.DDS for upper.dds), which is why a test that only patched isfile passed without the fix.

Tested

  • python -I tests/test_gallery.py: 32 tests OK with the fix; on main's tools/gallery.py the new test fails (HTTP Error 404: Texture not found, 1 error of 32).
  • python -I tests/test_text_write_line_endings.py: 3 tests OK.
  • python -I scripts/check_no_game_data.py tools/gallery.py tests/test_gallery.py: clean.

Run on Windows 11, Python 3.14.

GPUs tested: n/a (CPU-only Python tests)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498962380 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2105). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-25T20:50:46Z. --- Claimed in the coordination issue as: GALLERY-THUMB-UPPERCASE-DDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7174150654) ### What and why From CrazyThiago's finding in the coordination issue: `tools/gallery.py` answers `/textures/<stem>.png` with a PNG made from `<stem>.dds` when no PNG exists, but it only tried the lowercase `.dds` name. On a case-sensitive filesystem a texture saved as `upper.DDS` is not `upper.dds`, so the catalog listed it and its thumbnail was a 404. When `<stem>.dds` is not a file, the handler now looks in the same folder for a file whose name matches it in any case (`dds_sibling`). The candidate is the path `safe_subpath` already resolved inside the textures folder, and the sibling is in that same folder, so the containment guarantee is unchanged. A name that matches nothing in any case is still a 404. The regression test makes `os.path.isfile` case-sensitive and stops `os.path.realpath` from correcting the name's case. On Windows `realpath` returns the real case (`upper.DDS` for `upper.dds`), which is why a test that only patched `isfile` passed without the fix. ### Tested - `python -I tests/test_gallery.py`: 32 tests OK with the fix; on `main`'s `tools/gallery.py` the new test fails (`HTTP Error 404: Texture not found`, 1 error of 32). - `python -I tests/test_text_write_line_endings.py`: 3 tests OK. - `python -I scripts/check_no_game_data.py tools/gallery.py tests/test_gallery.py`: clean. Run on Windows 11, Python 3.14. GPUs tested: n/a (CPU-only Python tests) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Tyrannys commented 2026-11-26 00:48:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-26T00:48:37Z.


Added symlink containment for the case-insensitive sibling (64671a8a7). This comes from ZroIsHere's Tyrannys/leonida#1 (GALLERY-DDS-SYMLINK-CONTAINMENT), with credit in the commit (Co-authored-by).

The hole: dds_sibling returned any same-folder entry that passed os.path.isfile, and isfile follows symlinks. So a symlink named escaped_upper.DDS in the textures folder could serve a DDS from outside it as escaped_upper.png. Each sibling found now goes through safe_subpath against the textures folder, like every other requested path.

test_dds_symlink_escape_is_forbidden now covers a lowercase link (escaped.dds, 403) and an uppercase one (escaped_upper.DDS, 404). A shared test helper makes isfile and realpath case-sensitive while still following symlinks. Without it, Windows realpath resolves escaped_upper.dds to the link and refuses it before the fallback runs, so the uppercase case would pass without the fix. The uppercase-thumbnail test uses the same helper.

Then merged upstream/main (no conflicts).

Tested on Windows 11, Python 3.14. Symlinks could be created, so the test ran and did not skip:

  • python -I tests/test_gallery.py: 32 tests OK.
  • The escape test on the previous head 831abc1c1's tools/gallery.py: fails, escaped_upper.DDS is served (200 != 404).
  • On main's tools/gallery.py: only the uppercase thumbnail test fails (404).
  • python -I tests/test_text_write_line_endings.py: 3 tests OK.
  • python -I scripts/check_no_game_data.py tools/gallery.py tests/test_gallery.py: clean.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7179135285 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2105#issuecomment-7179135285). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-26T00:48:37Z. --- Added symlink containment for the case-insensitive sibling (`64671a8a7`). This comes from ZroIsHere's Tyrannys/leonida#1 (GALLERY-DDS-SYMLINK-CONTAINMENT), with credit in the commit (`Co-authored-by`). The hole: `dds_sibling` returned any same-folder entry that passed `os.path.isfile`, and `isfile` follows symlinks. So a symlink named `escaped_upper.DDS` in the textures folder could serve a DDS from outside it as `escaped_upper.png`. Each sibling found now goes through `safe_subpath` against the textures folder, like every other requested path. `test_dds_symlink_escape_is_forbidden` now covers a lowercase link (`escaped.dds`, 403) and an uppercase one (`escaped_upper.DDS`, 404). A shared test helper makes `isfile` and `realpath` case-sensitive while still following symlinks. Without it, Windows `realpath` resolves `escaped_upper.dds` to the link and refuses it before the fallback runs, so the uppercase case would pass without the fix. The uppercase-thumbnail test uses the same helper. Then merged `upstream/main` (no conflicts). Tested on Windows 11, Python 3.14. Symlinks could be created, so the test ran and did not skip: - `python -I tests/test_gallery.py`: 32 tests OK. - The escape test on the previous head `831abc1c1`'s `tools/gallery.py`: fails, `escaped_upper.DDS` is served (`200 != 404`). - On `main`'s `tools/gallery.py`: only the uppercase thumbnail test fails (404). - `python -I tests/test_text_write_line_endings.py`: 3 tests OK. - `python -I scripts/check_no_game_data.py tools/gallery.py tests/test_gallery.py`: clean. AI-assisted (Claude Code).
DeadlyChirp commented 2026-11-26 10:01:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T10:01:48Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_gallery.py: 30 passed, 2 skipped, 129 subtests passed. Both skips are symlink cases (Developer Mode is off, WinError 1314), not related to this change.

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7188812220 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2105#issuecomment-7188812220). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-26T10:01:48Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_gallery.py`: 30 passed, 2 skipped, 129 subtests passed. Both skips are symlink cases (Developer Mode is off, WinError 1314), not related to this change. (AI-assisted test run; output checked by hand.)
Tyrannys commented 2026-11-28 12:41:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T12:41:39Z.


Closing to free a PR slot for runtime work. This is gallery tooling only, and the branch stays on the fork if anyone wants it back. Thanks @DeadlyChirp for testing it. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239402658 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2105#issuecomment-7239402658). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T12:41:39Z. --- Closing to free a PR slot for runtime work. This is gallery tooling only, and the branch stays on the fork if anyone wants it back. Thanks @DeadlyChirp for testing it. AI-assisted (Claude Code).

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!2105
No description provided.