Skip to content

Wait for the LF when a chunk-size line splits on the CR - #912

Merged
benoitc merged 1 commit into
masterfrom
fix/chunk-size-split-crlf
Jul 16, 2026
Merged

Wait for the LF when a chunk-size line splits on the CR#912
benoitc merged 1 commit into
masterfrom
fix/chunk-size-split-crlf

Conversation

@benoitc

@benoitc benoitc commented Jul 16, 2026

Copy link
Copy Markdown
Owner

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/3 now treats the lone trailing \r as incomplete and waits for the \n.

While validating, the failure on master turned out to be a case_clause crash rather than a clean error: te_chunked/2 handled neither read_size/3's error nor read_chunk/2's {error, poorly_formatted_chunked_size}. Both now propagate through transfer_decode/2, and the te_chunked/2 spec 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant