arturobernalg opened a new pull request, #965:
URL: https://github.com/apache/httpcomponents-client/pull/965

   Follow-up to #942, which fixed the server read thread spinning forever on a 
BFINAL-terminated DEFLATE block in permessage-deflate. That fix left two 
residual gaps in the same code path, not a regression against it (before #942, 
a BFINAL block broke the message outright on both counts):
   
   1. `reset()` without `setDictionary()` drops the LZ77 window a later block, 
or a later message under context takeover, is entitled to back-reference. RFC 
7692 7.2.2 (MUST): "decompress each new message using the LZ77 sliding window 
used to process the last compressed message". Reproduced with the RFC's own 
literal wire vectors (7.2.3.4's BFINAL "Hello" followed by 7.2.3.2's 
context-takeover "Hello") against a real `WebSocketServer` and a hand-rolled 
RFC 6455 client: `DataFormatException: invalid distance too far back`, 
connection closed 1002.
   2. A BFINAL message missing the trailing `0x00` octet section 7.2.3.4 
requires (a non-conformant sender, but one worth tolerating - the typical raw 
`Deflater.finish()`) leaves only this method's own synthetic sync-flush tail 
unconsumed; feeding just that into the reset inflater leaves it mid-header, 
corrupting whatever is decoded next, independent of any LZ77 window sharing.
   Fix: a 32 KiB ring buffer (`WebSocketSlidingWindow`) re-primes the 
dictionary on each mid-stream reset; the reset inflater is only fed again when 
more than the synthetic tail remains. Applied to both decoders (server 
`PerMessageDeflateExtension`, client `PerMessageDeflate`).
   
   Tested beyond the unit/E2E suite added here: both decoders went through the 
project's own runnable WebSocket examples (`WebSocketEchoServer`/`Client`, 
H1.1; `WebSocketH2EchoServer`/`Client`, H2 cleartext via RFC 8441 Extended 
CONNECT) with no regression, plus a probe exercising permessage-deflate with 
context takeover over H2 specifically (3 consecutive large messages on one 
connection) - confirmed the H2 path reuses the same extension classes fixed 
here, not a separate implementation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to