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

Open
github-bot wants to merge 4 commits from github-bot/gh-2105 into main AGit
Owner

@⁠Tyrannys on GitHub · 2026-11-25 20:50 UTC · original
Tyrannys:gallery-uppercase-dds → main · +90 −6 · 2 files · 4 commits · open

Claimed in the coordination issue as: GALLERY-THUMB-UPPERCASE-DDS (#1608)

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

**@⁠Tyrannys** on GitHub · 2026-11-25 20:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2105) `Tyrannys:gallery-uppercase-dds` → `main` · +90 −6 · 2 files · 4 commits · open Claimed in the coordination issue as: GALLERY-THUMB-UPPERCASE-DDS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
The /textures/<stem>.png fallback only tried <stem>.dds. On a
case-sensitive filesystem a texture saved as upper.DDS was missed and
its thumbnail was a 404. When <stem>.dds is not a file, look for a file
in the same folder whose name matches it in any case. The sibling stays
in the folder safe_subpath already resolved.

The regression test makes isfile case-sensitive and stops realpath from
correcting the name's case (Windows realpath returns upper.DDS), so it
fails without the fix on every OS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows realpath returns upper.DDS for upper.dds, so a test that only
made isfile case-sensitive passed without the fix. The stand-in realpath
keeps the requested case, and the test now fails on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dds_sibling returned any same-folder entry that passed os.path.isfile,
which follows symlinks, so a symlink named escaped_upper.DDS could serve
a DDS from outside the textures folder as escaped_upper.png. Each
sibling it finds now goes through safe_subpath against the textures
folder, like every other requested path.

test_dds_symlink_escape_is_forbidden covers a lowercase and an
uppercase symlink. A shared stand-in makes isfile and realpath
case-sensitive while still following symlinks, so the uppercase case
reaches the sibling search on Windows and macOS too (there realpath
would otherwise resolve escaped_upper.dds to the link and refuse it
before the fallback runs).

Found and first fixed by ZroIsHere in Tyrannys/leonida#1
(GALLERY-DDS-SYMLINK-CONTAINMENT).

Co-authored-by: ZroIsHere <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:04 +00:00
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-26 00:48 UTC · original

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

**@⁠Tyrannys** on GitHub · 2026-11-26 00:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2105#issuecomment-7179135285) 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).
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-26 10:01 UTC · original · edited 2026-11-26 10:30 UTC

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

**@⁠DeadlyChirp** on GitHub · 2026-11-26 10:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2105#issuecomment-7188812220) · edited 2026-11-26 10:30 UTC 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.)
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/2105/head:github-bot/gh-2105'
git switch 'github-bot/gh-2105'

Merge

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