fix: reject truncated downloads#206
Merged
NianJiuZst merged 1 commit intoJul 18, 2026
Merged
Conversation
shaoohh
marked this pull request as ready for review
July 18, 2026 17:58
NianJiuZst
reviewed
Jul 18, 2026
NianJiuZst
left a comment
Collaborator
There was a problem hiding this comment.
This is a reasonable defense-in-depth check: the implementation preserves the existing destination, removes partial files, and avoids comparing decoded response bytes against compressed Content-Length values. I could not reproduce silent truncation with Node, Undici, or Bun because their fetch implementations already reject premature EOF, so I would frame this as hardening rather than a confirmed production bug; otherwise the focused and full test suites pass, and this looks good to merge once Actions are approved and green.
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.
Summary
Content-Lengthbefore atomically replacing the destinationContent-EncodingresponsesRoot cause
The downloader handled explicit stream errors, but a response that ended cleanly before delivering its declared byte count was accepted. The partial temporary file was then renamed to the final destination, silently producing a corrupt artifact.
Impact
Image, video, and other shared downloader users no longer receive silently truncated files when a server or intermediary closes a response early.
Validation
bun test test/files/download.test.tsbun run typecheckbun run lint(no errors; two pre-existing warnings)bun testbun run build:devRefs #79 (item 6: network truncation goes undetected)
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.