Skip to content

Validate HTTP request lengths and emit one response length - #653

Merged
bsergean merged 4 commits into
masterfrom
fix/http-request-framing
Nov 17, 2026
Merged

bsergean merged 4 commits into
masterfrom
fix/http-request-framing

Conversation

@bsergean

@bsergean bsergean commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

HTTP request parsing accepts partially valid Content-Length values such as 1x, +1 and 1, 2. Response serialization always generates a length header and then writes a caller-supplied one too, potentially emitting contradictory lengths.

Require an unsigned decimal request length to consume the entire parsed value, retaining the existing range checks. Trim legal leading spaces/tabs from HTTP header values so strict length validation still accepts normal HTTP whitespace. Emit one generated response Content-Length matching the actual body and skip the caller's duplicate, preserving other custom headers.

Validation: in-memory request/response fixtures cover malformed values, legal leading tabs, padded decimal lengths, and both matching/conflicting custom response lengths. The regression tests produce 10 failing assertions on master; all 158 HTTP assertions pass with the fix. New cases measure under 1 ms and use no sockets, sleeps or timeout waits. Combined plain-socket suite: 30/30 passed; targeted ASan/UBSan and MinGW compilation checks passed. Strict C++11 production build, formatting and diff checks passed.

The OpenSSL TSan failures were reproduced on current master and reduced to a standalone C++11 program using only std::thread and errno, without IXWebSocket or OpenSSL. Concurrent groups creating/joining short-lived threads cause Darwin TSan to attribute a previous thread's error-state access to a later thread reusing the same storage.

Both this PR and #653/#651 now carry the same narrow workaround: disable plain-memory TSan instrumentation only inside Socket::getErrno() and Socket::setErrno() on Apple Clang. Each function touches only OS thread-local error state. Callers, socket fields, locks and the rest of the library remain instrumented. A new thread-isolation regression test takes about 1 ms locally.

Validation of the workaround: the standalone errno reproducer is clean; an otherwise identical control with an intentional shared-variable race still reports that race. The formerly failing SOCKS5 binary passed ten consecutive TSan runs (9 seconds total). No retries, global suppressions or sleeps were added to CI.

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