Skip to content

http-api: advance readerIndex in FormUrlEncodedSerializer.deserialize - #3733

Merged
idelpivnitskiy merged 2 commits into
apple:mainfrom
bardrop:formurlencoded-advance-reader-index
Nov 14, 2026
Merged

idelpivnitskiy merged 2 commits into
apple:mainfrom
bardrop:formurlencoded-advance-reader-index

Conversation

@bardrop

@bardrop bardrop commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Deserializer says the readerIndex() will be advanced to show the content that was consumed. FormUrlEncodedSerializer.deserialize read the buffer with toString(charset), which does not move the index, so callers saw the whole form as still readable.

Modifications

  • Skip the readable bytes only after a successful decode, like ProtobufSerializer, so a failure leaves the buffer untouched.
  • Deprecated FormUrlEncodedHttpDeserializer now delegates to FormUrlEncodedSerializer.deserialize, so it also advances readerIndex.
  • Add FormUrlEncodedSerializerTest for heap and direct buffers: the index ends at the writer index, decoding starts at the current reader index, a serialize/deserialize round trip leaves nothing readable, and malformed input (a=%zz) leaves readerIndex unchanged.
  • Add a FormUrlEncodedHttpDeserializerTest case that checks the deprecated deserializer advances readerIndex.

Result

FormUrlEncodedSerializer.deserialize and the deprecated FormUrlEncodedHttpDeserializer consume the bytes they decode.

Fixes #3732

#### Motivation

`Deserializer` says the `readerIndex()` will be advanced to show the
content that was consumed. `FormUrlEncodedSerializer.deserialize` read
the buffer with `toString(charset)`, which does not move the index, so
callers saw the whole form as still readable (#3732).

#### Modifications

- Skip the readable bytes after decoding them to a `String`, the same
  way `AbstractStringSerializer` does.
- Add `FormUrlEncodedSerializerTest` for heap and direct buffers: the
  index ends at the writer index, decoding starts at the current reader
  index, and a serialize/deserialize round trip leaves nothing readable.

#### Result

`FormUrlEncodedSerializer.deserialize` consumes the bytes it decodes.

Fixes #3732

@idelpivnitskiy idelpivnitskiy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the contribution!

#### Motivation

Review on #3733: `decodeQueryParams` can throw (bad escape, too many
params), but the bytes were skipped before decoding. Also the deprecated
`FormUrlEncodedHttpDeserializer` kept its own copy of the decode logic
and still did not advance `readerIndex()`.

#### Modifications

- `FormUrlEncodedSerializer.deserialize` skips the readable bytes only
  after `decodeQueryParams` returns, like `ProtobufSerializer`.
- `FormUrlEncodedHttpDeserializer` delegates to
  `FormUrlEncodedSerializer.deserialize(buffer, charset)`.
- Tests: malformed input leaves `readerIndex()` unchanged; the deprecated
  deserializer advances `readerIndex()`.

#### Result

A failed decode leaves the buffer as it was, and both deserializers
consume the bytes they decode.
@bardrop

bardrop commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

The red JDK 11 job is DnsServiceDiscovererObserverTest.aQueryResolutionResultNewIPsAvailable ("Unexpected TTL value") in dns-discovery-netty, which this PR doesn't touch. Looks like the known flake from #1299 (#3694 is the fix); the other JDK jobs were cancelled by fail-fast. Could someone rerun it when you get a chance? I can't trigger reruns from a fork.

@idelpivnitskiy idelpivnitskiy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@idelpivnitskiy
idelpivnitskiy merged commit 3a88308 into apple:main Nov 14, 2026
16 of 22 checks passed
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.

http-api: FormUrlEncodedSerializer doesn't advance readerIndex

2 participants