Repository navigation
Auto-port 4.1: Stop DateFormatter trailing token from running past the parse end - #16968
Merged
Merged
Conversation
…6958) ## Problem `DateFormatter.parseHttpDate(txt, start, end)` is documented to parse only the `[start, end)` substring. Its tokenizer loop correctly stops at `end`, but the **trailing token** — the one still open when the loop finishes — was terminated at `txt.length()` instead of `end`: ```java // terminate trailing token return tokenStart != -1 && parseToken(txt, tokenStart, txt.length()); ``` When `end < txt.length()` and the date's *last* token is the one that completes the parse, the trailing token swallows the bytes after `end` and fails to parse. This is reachable in practice through cookies. A `Set-Cookie` header like `foo=bar; Expires=<date>; Path=/` makes `ClientCookieDecoder` call `parseHttpDate(header, start, end)` with `end` pointing at the `;` before `Path`. RFC 6265 §5.1.1 cookie-date tokens are **order-independent**, so a valid date whose year (or day) is the last token — e.g. `Sun 08:49:37 06 Nov 1994` — parses fine in isolation but returns `null` as a substring, silently dropping the expiry and downgrading the cookie to a session cookie. Standard `Sun, 06 Nov 1994 08:49:37 GMT` ordering does not trigger it (the time token completes the parse mid-loop, before the trailing `GMT`), which is why existing tests miss it. ## Fix Terminate the trailing token at `end` rather than `txt.length()`. Since `end <= txt.length()` always, this only ever shrinks the trailing token to the intended bound; the full-string `parseHttpDate(txt)` path (where `end == txt.length()`) is unaffected. Added a `DateFormatterTest` case that parses such a date both in isolation and as a substring and asserts they agree. ## Result `parseHttpDate` honours the `end` bound for the trailing token; valid order-independent cookie dates followed by other attributes now parse correctly. Full `DateFormatterTest` (14) passes. (cherry picked from commit 692d23f)
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
Oct 24, 2026
…e parse end (netty#16968) Auto-port of netty#16958 to 4.1 Cherry-picked commit: 692d23f --- ## Problem `DateFormatter.parseHttpDate(txt, start, end)` is documented to parse only the `[start, end)` substring. Its tokenizer loop correctly stops at `end`, but the **trailing token** — the one still open when the loop finishes — was terminated at `txt.length()` instead of `end`: ```java // terminate trailing token return tokenStart != -1 && parseToken(txt, tokenStart, txt.length()); ``` When `end < txt.length()` and the date's *last* token is the one that completes the parse, the trailing token swallows the bytes after `end` and fails to parse. This is reachable in practice through cookies. A `Set-Cookie` header like `foo=bar; Expires=<date>; Path=/` makes `ClientCookieDecoder` call `parseHttpDate(header, start, end)` with `end` pointing at the `;` before `Path`. RFC 6265 §5.1.1 cookie-date tokens are **order-independent**, so a valid date whose year (or day) is the last token — e.g. `Sun 08:49:37 06 Nov 1994` — parses fine in isolation but returns `null` as a substring, silently dropping the expiry and downgrading the cookie to a session cookie. Standard `Sun, 06 Nov 1994 08:49:37 GMT` ordering does not trigger it (the time token completes the parse mid-loop, before the trailing `GMT`), which is why existing tests miss it. ## Fix Terminate the trailing token at `end` rather than `txt.length()`. Since `end <= txt.length()` always, this only ever shrinks the trailing token to the intended bound; the full-string `parseHttpDate(txt)` path (where `end == txt.length()`) is unaffected. Added a `DateFormatterTest` case that parses such a date both in isolation and as a substring and asserts they agree. ## Result `parseHttpDate` honours the `end` bound for the trailing token; valid order-independent cookie dates followed by other attributes now parse correctly. Full `DateFormatterTest` (14) passes. Co-authored-by: Guimu <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
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.
Auto-port of #16958 to 4.1
Cherry-picked commit: 692d23f
Problem
DateFormatter.parseHttpDate(txt, start, end)is documented to parse only the[start, end)substring. Its tokenizer loop correctly stops atend, but the trailing token — the one still open when the loop finishes — was terminated attxt.length()instead ofend:When
end < txt.length()and the date's last token is the one that completes the parse, the trailing token swallows the bytes afterendand fails to parse.This is reachable in practice through cookies. A
Set-Cookieheader likefoo=bar; Expires=<date>; Path=/makesClientCookieDecodercallparseHttpDate(header, start, end)withendpointing at the;beforePath. RFC 6265 §5.1.1 cookie-date tokens are order-independent, so a valid date whose year (or day) is the last token — e.g.Sun 08:49:37 06 Nov 1994— parses fine in isolation but returnsnullas a substring, silently dropping the expiry and downgrading the cookie to a session cookie.Standard
Sun, 06 Nov 1994 08:49:37 GMTordering does not trigger it (the time token completes the parse mid-loop, before the trailingGMT), which is why existing tests miss it.Fix
Terminate the trailing token at
endrather thantxt.length(). Sinceend <= txt.length()always, this only ever shrinks the trailing token to the intended bound; the full-stringparseHttpDate(txt)path (whereend == txt.length()) is unaffected.Added a
DateFormatterTestcase that parses such a date both in isolation and as a substring and asserts they agree.Result
parseHttpDatehonours theendbound for the trailing token; valid order-independent cookie dates followed by other attributes now parse correctly. FullDateFormatterTest(14) passes.