Reject overflowing HPACK integers#9401
Conversation
Decode HPACK integers in Long and reject values that would overflow Int. This prevents malformed header indexes, dynamic table size updates, and string lengths from wrapping into negative or attacker-chosen small positive values.
|
It doesn't sound like this materially changes the logic or avoids security issues, but does more closely follow the spec https://datatracker.ietf.org/doc/html/rfc7541#section-5.1
|
|
@yschimke: Agreed, this is primarily a spec-compliance / parser-hardening change, which seems more aligned with RFC 7541 §5.1. The material difference is that malformed overlong HPACK integers now fail in |
Summary. Reject malformed HPACK integers before they overflow in
Hpack.Reader.readInt().Problem.
readInt()decodes HPACK continuation bytes into a signed 32-bit Int without bounding the number of continuation bytes or checking for overflow. An overlong HPACK integer can therefore wrap into a negative or unrelated small positive value, and malformed input is only rejected later by downstream parsing logic.Impact. An HTTP/2 peer can use those malformed HPACK integers to cause connection-level DoS or to make OkHttp accept invalid HPACK state transitions that a compliant decoder should reject.
Fix. This change hardens
readInt()by:Int.MAX_VALUEIOException("HPACK integer overflow")Valid HPACK integers are unchanged, including the existing max 31-bit case.
Tests. Added regression coverage in HpackTest for malformed HPACK integers that previously overflowed or wrapped:
Also updated the existing “insidious” HPACK tests to assert the new fail-fast behavior.