Repository navigation
Fix possible overflow in WriteToStream - #137242
Merged
elinor-fung merged 1 commit intoNov 11, 2026
Merged
Conversation
WriteToStream contains a cast of `long length` to `int`. This leads to an overflow when the incoming file length is > 2 GB. `(int)length - pos` becomes negative and `bytesRequested` gets negative. The code earlies out in the condition `if (bytesRequested <= 0)` without an error. The fix correctly calculates `length - pos` as long and only casts the result of the Math.Min operation to int. As the 2nd parameter is small (bufSize = 16k); there should not be an overflow of `bytesRequested` anymore until we reach a file length of 8192 PB.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
3 tasks
Member
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
Member
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
This was referenced Nov 11, 2026
Member
|
@HEllRZA Were you able to confirm that nothing else in your E2E scenario fails after this fix? That is, once we correctly produce a 2GB+ binary, does it run properly? We're looking at backporting and would like to check that it fixes your full scenario (beyond the reflection-based minimal repro you provided in the issue). |
Contributor
Author
|
@elinor-fung |
JulieLeeMSFT
pushed a commit
that referenced
this pull request
Nov 21, 2026
…137383) Backport of #137242 to release/11.0 /cc @elinor-fung @HEllRZA ## Customer Impact - [x] Customer reported - [ ] Found internally Issue: #137187 Publishing as single-file produces an empty executable above 2GB. There is no warning/error about the incorrect output. ## Regression - [x] Yes - [ ] No Pre-existing bug, but exposed via changes in how the bundler writes out the single-file host in .NET 10. ## Testing Manual ## Risk Low Co-authored-by: Bernd Eckstein <[email protected]>
JulieLeeMSFT
pushed a commit
that referenced
this pull request
Nov 21, 2026
…137384) Backport of #137242 to release/10.0 /cc @elinor-fung @HEllRZA ## Customer Impact - [x] Customer reported - [ ] Found internally Issue: #137187 Publishing as single-file produces an empty executable above 2GB. There is no warning/error about the incorrect output. ## Regression - [x] Yes - [ ] No Pre-existing bug, but exposed via changes in how the bundler writes out the single-file host in .NET 10. ## Testing Manual ## Risk Low Co-authored-by: Bernd Eckstein <[email protected]>
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.
WriteToStreamcasts the file length fromlongtointbeforecalculating the remaining bytes. For files larger than
int.MaxValue(2 GiB), this can produce a negative
bytesRequested,causing the method to exit without reporting an error or copying the
complete file. The
intposition counter also cannot represent offsetsbeyond this limit.
This fix uses a
longposition counter and calculates the remaininglength using 64-bit arithmetic. It casts the result to
intonly afterMath.Mincaps the requested size to the 16 KiB buffer.fixes #137187