Skip to content

Fix SETTINGS_HEADER_TABLE_SIZE handling in OkHttp transport - #12818

Merged
AgraVator merged 6 commits into
grpc:masterfrom
kenkangxgwe:hpack-fix
Dec 2, 2026
Merged

AgraVator merged 6 commits into
grpc:masterfrom
kenkangxgwe:hpack-fix

Conversation

@kenkangxgwe

@kenkangxgwe kenkangxgwe commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

In the OkHttp transport, the client and server were not applying the SETTINGS_HEADER_TABLE_SIZE setting received from the peer to their HPACK encoder (Hpack.Writer). This could lead to protocol errors if the peer requested a smaller table size than the default (4096 octets).

This change modifies Http2.Writer.ackSettings to resize the HPACK writer table when this setting is received, ensuring compliance with peer limits and triggering the required Dynamic Table Size Update in the next HEADERS frame.

Fixes #12819.

In the OkHttp transport, the client and server were not applying the
SETTINGS_HEADER_TABLE_SIZE setting received from the peer to their HPACK
encoder (Hpack.Writer). This could lead to protocol errors if the peer
requested a smaller table size than the default (4096 octets).

This change modifies Http2.Writer.ackSettings to resize the HPACK writer
table when this setting is received, ensuring compliance with peer limits
and triggering the required Dynamic Table Size Update in the next HEADERS
frame.
@kannanjgithub

Copy link
Copy Markdown
Contributor

/gcbrun

…t32 bounds

- Stop mutating hpackReader on incoming peer SETTINGS_HEADER_TABLE_SIZE in Http2.Reader.readSettings(), and make Hpack.Reader.headerTableSizeSetting final so peers cannot shrink or expand our decoder dynamic table.
- Use Settings.isSet(Settings.HEADER_TABLE_SIZE) in Http2.Writer.ackSettings() instead of checking >= 0, so 0xFFFFFFFF (uint32 max) is not treated as unset.
- Treat SETTINGS_HEADER_TABLE_SIZE as unsigned uint32 in Hpack.Writer.resizeHeaderTable() using (& 0xffffffffL) so values >= 2^31 clamp to SETTINGS_HEADER_TABLE_SIZE_LIMIT (16384) instead of going negative.
- Fix evictToRecoverBytes() loop bound (j > nextDynamicTableIndex) and null out evicted dynamicTable slots in both Hpack.Reader and Hpack.Writer.
- Saturate unsigned uint32 SETTINGS_MAX_CONCURRENT_STREAMS (>= 2^31) to Integer.MAX_VALUE in OkHttpClientTransport.
- Add unit and transport tests covering header table size 0, 0x7FFFFFFF, 0x80000000, 0xFFFFFFFF, empty SETTINGS, consecutive shrink-then-grow updates, slot eviction clearing, and MAX_CONCURRENT_STREAMS = 0xFFFFFFFF.
…t32 bounds

- Stop mutating hpackReader on incoming peer SETTINGS_HEADER_TABLE_SIZE in Http2.Reader.readSettings(), and make Hpack.Reader.headerTableSizeSetting final so peers cannot shrink or expand our decoder dynamic table.
- Use Settings.isSet(Settings.HEADER_TABLE_SIZE) in Http2.Writer.ackSettings() instead of checking >= 0, so 0xFFFFFFFF (uint32 max) is not treated as unset.
- Treat SETTINGS_HEADER_TABLE_SIZE as unsigned uint32 in Hpack.Writer.resizeHeaderTable() using (& 0xffffffffL) so values >= 2^31 clamp to SETTINGS_HEADER_TABLE_SIZE_LIMIT (16384) instead of going negative.
- Fix evictToRecoverBytes() loop bound (j > nextDynamicTableIndex) and null out evicted dynamicTable slots in both Hpack.Reader and Hpack.Writer.
- Saturate unsigned uint32 SETTINGS_MAX_CONCURRENT_STREAMS (>= 2^31) to Integer.MAX_VALUE in OkHttpClientTransport.
- Add unit and transport tests covering header table size 0, 0x7FFFFFFF, 0x80000000, 0xFFFFFFFF, empty SETTINGS, consecutive shrink-then-grow updates, slot eviction clearing, and MAX_CONCURRENT_STREAMS = 0xFFFFFFFF.
…ff minimal

- Saturate unsigned 32-bit SETTINGS values (>= 2^31) to Integer.MAX_VALUE directly in Http2.Reader.readSettings() for HEADER_TABLE_SIZE, MAX_CONCURRENT_STREAMS, and MAX_HEADER_LIST_SIZE.
- Drop separate consumer-side saturation and unrelated Hpack.java edits so the PR only modifies Http2.java in production code.
- Add Http2Test coverage verifying 0x80000000 and 0xFFFFFFFF saturation for HEADER_TABLE_SIZE, MAX_CONCURRENT_STREAMS, and MAX_HEADER_LIST_SIZE.
@kannanjgithub kannanjgithub added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 1, 2026
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 1, 2026
Remove dead Hpack.Reader.headerTableSizeSetting(int) and make
headerTableSizeSetting final now that Http2.Reader.readSettings no
longer mutates the decoder table size on peer SETTINGS frames. Update
HpackTest.tooLargeToHPackIsStillEmitted to construct Hpack.Reader with a
limit of 1 directly.
@AgraVator AgraVator added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 2, 2026
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 2, 2026
@AgraVator
AgraVator merged commit 492a964 into grpc:master Dec 2, 2026
17 of 18 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.

okhttp: Optimize HPACK to index :path (reverted #12799)

4 participants