Skip to content

Only accept a chunk size at the start of the chunk-size line - #364

Merged
mame merged 1 commit into
ruby:masterfrom
mame:chunk-size-line
Nov 25, 2026
Merged

mame merged 1 commit into
ruby:masterfrom
mame:chunk-size-line

Conversation

@mame

@mame mame commented Nov 13, 2026

Copy link
Copy Markdown
Member

read_chunked took the first run of hex digits anywhere in the line, so lines such as "0x1f" or ";ext=1f" were read as different sizes. Require the size at the start of the line, followed only by optional whitespace and a chunk extension, as RFC 9112 does.

Co-authored-by: Clément Joubert (https://hackerone.com/czjfr)

@shioimm shioimm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall.

This regex still accepts trailing spaces after the chunk size (e.g. "1f ").
This is not in the RFC grammar, but some other implementations accept it (e.g. CPython's http.client does rstrip() in _read_next_chunk_size: https://github.com/python/cpython/blob/main/Lib/http/client.py ).
If we reject it, we might break interop if there are servers that send trailing spaces. So I think it is fine to leave it as it is.

nit: line[/.../] and line.slice(/.../) do the same thing. Using .slice like the original code makes the diff smaller. But either is fine.

read_chunked took the first run of hex digits anywhere in the line, so
lines such as "0x1f" or ";ext=1f" were read as different sizes.  Require
the size at the start of the line, followed only by optional whitespace
and a chunk extension, as RFC 9112 does.

Co-authored-by: Clément Joubert (https://hackerone.com/czjfr)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame

mame commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Thank you for looking into other implementations too! I changed it to use slice. I'll merge it.

@mame
mame merged commit aa45648 into ruby:master Nov 25, 2026
26 checks passed
@mame
mame deleted the chunk-size-line branch November 25, 2026 16:22
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.

2 participants