Skip to content

Validate Content-Length is non-negative in parse_form#297

Merged
Kludex merged 2 commits into
mainfrom
reject-negative-content-length
Jun 4, 2026
Merged

Validate Content-Length is non-negative in parse_form#297
Kludex merged 2 commits into
mainfrom
reject-negative-content-length

Conversation

@Kludex
Copy link
Copy Markdown
Owner

@Kludex Kludex commented Jun 4, 2026

Summary

parse_form() parsed the Content-Length header into an int without checking its sign. A negative value made the bounded chunked read min(content_length - bytes_read, chunk_size) go negative, so input_stream.read(-1) read the whole stream in one call instead of in chunks. This adds a guard rejecting negative Content-Length, mirroring the existing chunk_size validation a few lines below.

Test

Added test_parse_form_negative_content_length; full suite passes (150 tests).

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

A negative `Content-Length` (e.g. `-1`) was parsed without sign
validation, so `min(content_length - bytes_read, chunk_size)` became
negative and `input_stream.read(-1)` drained the whole stream into
memory at once, bypassing the chunked-read limit (GHSA-v9pg-7xvm-68hf).
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 4, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing reject-negative-content-length (1356d2e) with main (6b837d4)

Open in CodSpeed

@Kludex Kludex changed the title Reject negative Content-Length in parse_form Reject negative Content-Length in parse_form Jun 4, 2026
@Kludex Kludex merged commit c814948 into main Jun 4, 2026
15 checks passed
@Kludex Kludex deleted the reject-negative-content-length branch June 4, 2026 08:18
@Kludex Kludex changed the title Reject negative Content-Length in parse_form Validate Content-Length is non-negative in parse_form Jun 4, 2026
@Kludex Kludex mentioned this pull request Jun 4, 2026
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.

1 participant