Skip to content

fix(storage): stop new uploads from overwriting a live entry's data - #321

Merged
LouisHaftmann merged 1 commit into
devfrom
fix/upload-folder-collision
Nov 23, 2026
Merged

LouisHaftmann merged 1 commit into
devfrom
fix/upload-folder-collision

Conversation

@LouisHaftmann

Copy link
Copy Markdown
Collaborator

📝 Summary

A new upload could overwrite another cache entry's data, and that key then served the wrong bytes without any error. The folder for an upload's Parts was named after its random 10-digit upload id, and nothing checked whether a live storage location already used that folder. A cache with ~190k entries and ~125k uploads a day hits about two of these collisions each day (#320).

Now every upload gets a UUID folder. The upload id stays the same random number for the upload URL. Readers take the folder from the stored folderName, so existing numeric folders keep working and no migration is needed.

 create_upload
   id = random_upload_id()            # ≤ 10 digits, still the upload URL id
-  folder_name = id.to_string()       # can equal a live location's folder
+  folder_name = Uuid::new_v4()       # its own folder

✅ Verification

New test an_upload_never_writes_into_a_live_folder_named_after_its_id:

create upload U
plant a live entry whose folder is named U.id, with bytes "live entry"
upload and complete U with bytes "new upload"
download the live entry -> expect "live entry"
  • Before: fails, the live entry returns new upload
  • After: passes

Two cleanup tests that assumed the folder name equals the upload id now read the upload's stored folder.

  • cargo +nightly fmt --check and cargo clippy --all-targets --locked: clean
  • cargo test: 84/84 on SQLite + filesystem and on Postgres + S3

🔍 Reviews

Each review ran on Opus 5.5, GPT 6.1 Sol and Gemini 4 Neon.

Review Found Fixed
Bug 0 0
Spec 0 0
Simplicity 0 0

🔗 Issues

Closes #320

💥 Merge danger

Door: two-way. Older versions also read the folder from the stored folderName, so a rollback still serves entries in UUID folders.

Blast Radius: uploads. Only how new upload folders are named changes. Hot paths make no extra round trips.

⚠️ Needs attention

Entries already corrupted by a collision stay corrupted. This fix stops new collisions only, and the server keeps no checksum it could use to find the bad entries. Deployments with many entries can clear their cache to be sure.

🤖 Generated with Claude Code

An upload's folder was named after its random ten-digit id, and nothing
checked that no live storage location used that folder. With many live
entries a new upload could draw a live folder's number and write its
Parts over that entry's data, so one key served another key's bytes.

Name each upload's folder with a UUID instead. The id stays the same
random number for the upload URL. Readers take the folder from the
stored folderName, so existing numeric folders keep working.

Closes #320

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LouisHaftmann
LouisHaftmann merged commit 0776999 into dev Nov 23, 2026
28 of 29 checks passed
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.

Upload folder ids can collide with a live entry's folder, so one key serves another key's bytes

1 participant