-
Notifications
You must be signed in to change notification settings - Fork 42
Improve bounds checks #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cowtowncoder it can lead to serious issues, see GHSA-cmp6-m4wj-q63q
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)