You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "Asthenia0412 (via GitHub)" <gi...@apache.org> on 2026/10/16 11:51:15 UTC

[PR] [improve][broker] Bound uncompressedSize before ByteBuf allocation in decompression path [pulsar]

Asthenia0412 opened a new pull request, #26938:
URL: https://github.com/apache/pulsar/pull/26938

   ## Motivation
   
   MessageMetadata.uncompressedSize is a client-controlled field. All codec decode() paths allocate ByteBuf directly from it without boundary checks, creating potential OOM vectors from malicious or corrupted messages. Additionally, codec decode() methods do not release the allocated ByteBuf when decompression throws an exception.
   
   ## Modifications
   
   ### Layer 2 — Bound check before ByteBuf allocation
   - `MessageParser.uncompressPayloadIfNeeded()`: guard uncompressedSize against maxMessageSize
   - Applied the same guard at all other decompression call sites (`ConsumerImpl`, broker-side compaction paths `RawBatchConverter`, `PulsarTopicCompactionService`)
   
   ### Layer 3 — ByteBuf release on codec exception
   All 4 compression codecs wrapped decode() to release the internally-allocated ByteBuf on decompression exceptions:
   - CompressionCodecLZ4
   - CompressionCodecZstd
   - CompressionCodecZLib
   - CompressionCodecSnappy
   
   ## Testing
   - Added unit tests for oversized uncompressedSize rejection
   - Added unit test verifying codec exception path does not leak ByteBuf
   - Existing test suite passes
   - Tested with: `./gradlew :pulsar-common:test --tests "*CompressorCodecTest*"`
   - Tested with: `./gradlew :pulsar-broker:test --tests "*.MessageParserTest.testUncompressPayloadRejects*"`
   
   ## Issue reference
   Closes #26442


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][broker] Bound uncompressedSize before ByteBuf allocation in decompression path [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26938:
URL: https://github.com/apache/pulsar/pull/26938#issuecomment-6218802203

   please check the comment related to the threat model, https://github.com/apache/pulsar/issues/26442#issuecomment-6218753160.
   
   Regardless, it would make sense to mitigate "zip bomb" attacks although it's not currently considered as a DoS vulnerability in Pulsar.


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org