Bound header field name size before validating#296
Merged
Conversation
Enforce the per-header size limit before slicing and bulk-validating the field name, so an over-limit name fails fast instead of copying and scanning the whole span. Fixes a regression from #295, which moved the size check after the slice/validate.
There was a problem hiding this comment.
No issues found across 1 file
Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more
Re-trigger cubic
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
Fixes a regression introduced in #295.
That PR rewrote
HEADER_FIELDto find the colon and validate the whole field-name span at once. The size check (advance_header_size) ran after slicing andtranslate-validating the span, so a header field name with no colon arriving in one largewrite()chunk got sliced and scanned in full before themax_header_sizelimit was applied - the limit no longer bounded the work or temporary allocation for an oversized name.This moves
advance_header_sizeto before the slice/validate, so an over-limit field name fails fast as it did prior to #295.For an 8 MiB field-name chunk with the default 4 KiB limit, parser-side temporary allocation drops from ~16 MiB back to ~4 KiB; behaviour for valid input is unchanged.
Correctness
tests/test_formparsers.py(40 tests) pass against this branch.AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.