Conversation
Can be a problem when reusing buffers and the buffer contains data from previous usage after the end index.
| public void releaseEncodeBuffer(byte[] buffer) | ||
| { | ||
| if (_encodingBuffer == null || (buffer != null && buffer.length > _encodingBuffer.length)) { | ||
| // Clear the buffer to protect against bugs which might leak the content during next use |
There was a problem hiding this comment.
Hmmmh. Not a big fan of defensive coding; plus, doing this will cancel much of performance benefits of buffer reuse.
Or, maybe worse, add overhead for case where there is no reuse.
There was a problem hiding this comment.
Actually, let's just remove these. If we really wanted, could add opt-in configuration for clearing but for now I don't think we should clear the buffers due to overhead.
There was a problem hiding this comment.
@cowtowncoder it can lead to serious issues, see GHSA-cmp6-m4wj-q63q
There was a problem hiding this comment.
Yes, in case of bug(s) that allow copy from outside legal area.
I will remove clearing from this PR: if there's reproduction of actual vulnerability can address that separately.
I would also be +1 for adding setting that simply disables recycling for most security conscious; that would avoid the issue even more reliably.
There was a problem hiding this comment.
Removed buffer clearing from this PR; as I said can be addressed in a follow-up as necessary.
There was a problem hiding this comment.
doing this will cancel much of performance benefits of buffer reuse
Fair point. But unlike GHSA-cmp6-m4wj-q63q, if there was a similar issue here in ning/compress, then it would always be an issue due to the automatic buffer reuse.
Though it seems LZF is not prone to the same offset == 0 bug because for LZF the offset is always + 1, see https://github.com/ning/compress/wiki/LZFFormat. So the risk here would be rather some other implementation bug or overflow.
Though at least during fuzzing I did not find any issues.
src/main/java/com/ning/compress/lzf/impl/UnsafeChunkEncoderBE.java
Outdated
Show resolved
Hide resolved
|
Just realized I messed up beautifully orchestrated individual commits. Sorry. Will still merge as separate. |
|
Ok this is merged with changes I discussed and I'd be ready for 1.2.0 release. But before doing that wanted to check anyone thinks further work is needed for before doing that (f.ex to address concerns about buffer recycling). @Marcono1234 @yawkat WDYT? |
I am not sure, but I think not. It seems most or all cases where Also a small note regarding 9265ebb, specifically this check: compress/src/main/java/com/ning/compress/lzf/ChunkDecoder.java Lines 110 to 113 in c9acc13 Unsafe access (so Unsafe out-of-bounds access is not a concern), and it throws an exception here so even if targetBuffer contains data which should not have been decompressed due to being out-of-bounds, it is not inspected by the user anyway.
The only (?) risk would be some side channel attack, that a malicious user can deduce information from different exceptions which occur before this check here. Or that despite the exception being thrown here, user-code still somehow uses the content from |
|
Ok. For now I consider this potentially releasable; but will wait a day or two just in case. |
As discussed @cowtowncoder, these are the changes for final review. If it is easier, you can review the commits individually.
If possible on merge please preserve the individual commits and don't squash them.
(CC @yawkat)