Skip to content

fix(http1): fix reading large bodies on 32-bit systems#4056

Merged
seanmonstar merged 1 commit intomasterfrom
sean/nqqkwzyowpux
Apr 27, 2026
Merged

fix(http1): fix reading large bodies on 32-bit systems#4056
seanmonstar merged 1 commit intomasterfrom
sean/nqqkwzyowpux

Conversation

@seanmonstar
Copy link
Copy Markdown
Member

@seanmonstar seanmonstar commented Apr 26, 2026

On 32-bit systems, the cast of the length to read from a u64 to a usize could
truncate, and cause less to be read. If the length was larger than usize::MAX,
the end could not be read.

To fix this, we use a saturating cast pattern instead.

Closes #4055

@cpud36
Copy link
Copy Markdown

cpud36 commented Apr 26, 2026

In extremely rare cases

Although it is not important, I believe it is guaranteed to happen if ever remaining becomes larger than usize::MAX. The code can never decrease remaining more than to_read, thus it cannot pass below the usize::MAX boundary...

@seanmonstar seanmonstar changed the title fix(http1): fix possibly short reads when decoding a large body fix(http1): fix reading large bodies on 32-bit systems Apr 27, 2026
@seanmonstar
Copy link
Copy Markdown
Member Author

You're right, I stepped through a bit more. I've adjusted the language and title.

On 32-bit systems, the cast of the length to read from a u64 to a usize could
truncate, and cause less to be read. If the length was larger than usize::MAX,
the end could not be read.

To fix this, we use a saturating cast pattern instead.

Closes #4055
@seanmonstar seanmonstar merged commit b12f652 into master Apr 27, 2026
22 checks passed
@seanmonstar seanmonstar deleted the sean/nqqkwzyowpux branch April 27, 2026 12:32
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.

u64->usize overflow in h1 decode on 32bit system

2 participants