Skip to content

Fix HTTP header value parsing: bounds check and robust trimming#574

Merged
bsergean merged 1 commit intomasterfrom
fix/http-header-parsing
May 1, 2026
Merged

Fix HTTP header value parsing: bounds check and robust trimming#574
bsergean merged 1 commit intomasterfrom
fix/http-header-parsing

Conversation

@bsergean
Copy link
Copy Markdown
Collaborator

@bsergean bsergean commented May 1, 2026

Summary

  • Add bounds check to the space-skipping while loop to prevent UB when the colon is near the end of the line
  • Replace the unsigned arithmetic (lineStr.size() - start - 2) with a trailing trim on the extracted value — avoids size_t underflow and correctly handles both \r\n and \n-only line endings
  • Fix isspace UB by casting to unsigned char in the lambda
  • Remove unused <locale> include

This is an alternative to #564 which identified the same root cause but introduced a redundant 1024-byte cap and used int in the isspace lambda (UB for negative char values).

Test plan

  • Existing test suite passes
  • Headers with empty values parse correctly
  • Headers with no trailing \r (Unix line endings) parse correctly

🤖 Generated with Claude Code

- Add bounds check to the space-skipping loop to prevent UB when
  the colon is near the end of the line
- Replace the unsigned arithmetic (size - start - 2) with a trim on
  the extracted value; avoids size_t underflow and correctly handles
  both \r\n and \n-only line endings
- Fix isspace UB by casting to unsigned char in the lambda
- Remove unused <locale> include

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bsergean bsergean merged commit ef55187 into master May 1, 2026
14 checks passed
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