Repository navigation
Validate HTTP request lengths and emit one response length - #653
Merged
Merged
Conversation
This was referenced Nov 17, 2026
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.
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::threadanderrno, 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()andSocket::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.