Wait for the LF when a chunk-size line splits on the CR#912
Merged
Conversation
A chunked response failed with {error, invalid_chunk_size} when the
CRLF ending a chunk-size line was split across two socket reads,
leaving the buffer on a lone \r. read_size/3 now treats that as
incomplete and waits for more data. te_chunked/2 also propagates the
errors of read_size/3 and read_chunk/2 instead of crashing with a
case_clause, and its spec now matches its real returns.
Fixes #901
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.
Fixes #901.
Chunked decoding failed with
{error, invalid_chunk_size}when the CRLF terminating a chunk-size line was split across two socket reads, leaving the parse buffer on a lone\r. Intermittent, more likely with large chunked bodies and TLS record fragmentation.read_size/3now treats the lone trailing\ras incomplete and waits for the\n.While validating, the failure on master turned out to be a
case_clausecrash rather than a clean error:te_chunked/2handled neitherread_size/3's error norread_chunk/2's{error, poorly_formatted_chunked_size}. Both now propagate throughtransfer_decode/2, and thete_chunked/2spec is corrected to its real returns.Tests drive the parser directly: the two split cases from the issue, an exhaustive split sweep of a two-chunk body with trailers at every byte position, and clean-error assertions for a malformed size line and chunk terminator.