xvrl opened a new pull request, #24304:
URL: https://github.com/apache/kafka/pull/24304

   Reads over TLS fail with `IllegalStateException: Buffer overflow when 
available data size (16384) >= application buffer size (16384)` when the TLS 
provider is BouncyCastle or Conscrypt, under TLS 1.2 and 1.3. Both report a 
16384-byte application buffer, so one full record fills `appReadBuffer` and the 
next unwrap overflows. SunJSSE reports a larger one and is not affected.
   
   Once `dst` is full, `SslTransportLayer.read()` now unwraps only records that 
fit after the leftover plaintext, and fails instead of spinning when an engine 
overflows an empty buffer.
   
   - Records that fit are still unwrapped after `dst` is full, so a peer's 
`close_notify` behind buffered requests is seen and a response to a client that 
closed fails right away.
   - The fit check uses the TLS record length, so no engine unwraps without 
room: on `BUFFER_OVERFLOW` Conscrypt consumes the record and keeps its 
plaintext. A record that doesn't fit, and any `close_notify` behind it, is left 
for the next read, the same as a record whose unwrap overflows.
   - An overflow into an empty buffer that could not grow throws instead of 
looping forever.
   
   Earlier attempts fall short: #9188 changes code after the throw, which still 
fires; #6495 skips the throw but unwraps without room, stalling Conscrypt; 
#6541/#6542 stop after each record, leaving `close_notify` unread; #5785 grows 
`appReadBuffer` past the session's size.
   
   Testing: real-engine tests with SunJSSE, BouncyCastle and Conscrypt, under 
TLS 1.2 and 1.3, cover full records after `dst` is full, a record with room 
after `dst` is full, and a deferred `close_notify`. BouncyCastle JSSE and 
Conscrypt are runtime-only test dependencies, loaded reflectively. Mock-engine 
tests cover an overflow with plaintext left in `appReadBuffer`, an engine that 
overflows an empty buffer, and a buffer that grows on overflow. The TLS peer of 
the existing `close_notify` tests is extracted into `TlsPeer` so both use it.
   
   Co-Authored-By: Claude Opus 5.5 <[email protected]>
   


-- 
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]

Reply via email to