Skip to content

Fix SETTINGS_HEADER_TABLE_SIZE handling in OkHttp transport - #12818

Open
kenkangxgwe wants to merge 3 commits into
grpc:masterfrom
kenkangxgwe:hpack-fix
Open

kenkangxgwe wants to merge 3 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.

This branch has not been deployed

No deployments
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)

3 participants