Repository navigation
Preview disk cache: ignore symlinked shard directories (#1504) - #1579
Merged
Merged
Conversation
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
pruneandcleardelete matching<32 hex>.jpgfiles out there.getandputwent through the same link too:getcould read an outside file and, when it didn't decode, delete it, andputcould write into the outside folder.Changes in
crates/preview/src/disk.rs:is_real_dirhelper (symlink_metadata(..).is_dir()): false for a symlink, and on Windows for a junction / symlink reparse point.scanskips a shard that isn't a real directory, sosize,pruneandclearnever see files behind it (checking the childDirEntry::metadata, as before, didn't catch a linked parent).gettreats a linked shard as a miss (no read, no deleting of an undecodable file);putrefuses to write into one.docs/whats-new.mdmention 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 thatsize,prune,get,putandclearall leave it alone. Without the fix it fails at the first assertion (sizecounts the sentinel), andprune/get/clearwould 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.