Skip to content

Drop a response whose Content-Length headers disagree - #2237

Merged
xroche merged 3 commits into
masterfrom
duplicate-content-length
Nov 14, 2026
Merged

xroche merged 3 commits into
masterfrom
duplicate-content-length

Conversation

@xroche

@xroche xroche commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

A response whose Content-Length headers give different values is now dropped and its connection closed, as RFC 9112 §6.3 requires. Before, the last value won, so a file could be saved cut short. Repeated equal values, including a list such as 16, 16, are still accepted. A Content-Length line too long to read whole also drops the response, because the value it hides cannot be compared. A single malformed value such as 16 bytes is still read as before.

xroche and others added 3 commits November 14, 2026 17:17
The header parser kept the last Content-Length it read, so a response
carrying "Content-Length: 16" and then "Content-Length: 8" was saved cut
at 8 bytes. RFC 9112 6.3 calls differing lengths an unrecoverable
framing error: the client must close the connection and discard the
response. hts_content_length_agrees() now compares each value with the
ones before it, including list values such as "16, 8". The header loop
in htsback.c fails the transfer when they differ. Equal repeats
stay accepted, as RFC 9110 8.6 allows.

A single malformed value such as "16 bytes" is still read leniently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
The helper stopped at the first element it could not read, so "16,,8"
and "16, x, 8" passed with the 8 never compared. It now skips empty
elements and text that is no number, and goes on to the next one. A
signed or oversized number counts as a length of its own. An over-long
Content-Length line that binput_line cuts counts as a conflict, because
the value it hides cannot be compared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
A 1xx block frames no body, so its lengths cannot desync anything, and
master accepted the final response that follows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche enabled auto-merge (squash) November 14, 2026 16:39
@xroche
xroche merged commit ea88752 into master Nov 14, 2026
41 checks passed
@xroche
xroche deleted the duplicate-content-length branch November 14, 2026 17:12
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