Skip to content

Preview disk cache: ignore symlinked shard directories (#1504) - #1579

Merged
echelon merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1504
Oct 14, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1504

Conversation

@MarekSpodBiedry

Copy link
Copy Markdown
Contributor

Fixes #1504.

The disk thumbnail cache walked any two-hex shard folder in its directory, so a shard that was a symlink (or a Windows junction) to an outside folder made prune and clear delete matching <32 hex>.jpg files out there. get and put went through the same link too: get could read an outside file and, when it didn't decode, delete it, and put could write into the outside folder.

Changes in crates/preview/src/disk.rs:

  • New is_real_dir helper (symlink_metadata(..).is_dir()): false for a symlink, and on Windows for a junction / symlink reparse point.
  • scan skips a shard that isn't a real directory, so size, prune and clear never see files behind it (checking the child DirEntry::metadata, as before, didn't catch a linked parent).
  • get treats a linked shard as a miss (no read, no deleting of an undecodable file); put refuses to write into one.
  • Module docs and docs/whats-new.md mention it, next to the issue Thumbnail cache cleanup deletes every file under thumbs/, not just its own thumbnails #98 rule the cache already follows.

Test: disk_cache_ignores_symlinked_shard_directories (unix only, since creating a symlink on Windows needs extra privileges) links a valid shard to an outside folder holding a matching sentinel file and checks that size, prune, get, put and clear all leave it alone. Without the fix it fails at the first assertion (size counts the sentinel), and prune/get/clear would delete it.

Not covered: an attacker swapping a shard for a link between the check and the file operation (the race the issue mentions). That needs directory-relative (openat-style) file operations, which std doesn't offer; this PR closes the static case.

@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you @MarekSpodBiedry! This landed on main in integration batch 35 (#1682).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview cache clear and prune traverse symlinked shard directories

2 participants