Skip to content

Commit

Permalink
Add checks for offset/size/length
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor authored and luben committed Jun 4, 2024
1 parent c88623b commit 7fd6382
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/github/luben/zstd/ZstdCompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Objects;

public class ZstdCompressCtx extends AutoCloseBase {

Expand Down Expand Up @@ -525,6 +526,8 @@ public int compressDirectByteBuffer(ByteBuffer dstBuff, int dstOffset, int dstSi
if (!dstBuff.isDirect()) {
throw new IllegalArgumentException("dstBuff must be a direct buffer");
}
Objects.checkFromIndexSize(srcOffset, srcSize, srcBuff.limit());
Objects.checkFromIndexSize(dstOffset, dstSize, dstBuff.limit());

acquireSharedLock();

Expand Down Expand Up @@ -560,6 +563,9 @@ public int compressDirectByteBuffer(ByteBuffer dstBuff, int dstOffset, int dstSi
* @return the number of bytes written into buffer 'dstBuff'.
*/
public int compressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize) {
Objects.checkFromIndexSize(srcOffset, srcSize, srcBuff.length);
Objects.checkFromIndexSize(dstOffset, dstSize, dstBuff.length);

ensureOpen();
acquireSharedLock();

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/github/luben/zstd/ZstdDecompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Objects;

public class ZstdDecompressCtx extends AutoCloseBase {

Expand Down Expand Up @@ -163,6 +164,8 @@ public int decompressDirectByteBuffer(ByteBuffer dstBuff, int dstOffset, int dst
if (!dstBuff.isDirect()) {
throw new IllegalArgumentException("dstBuff must be a direct buffer");
}
Objects.checkFromIndexSize(srcOffset, srcSize, srcBuff.limit());
Objects.checkFromIndexSize(dstOffset, dstSize, dstBuff.limit());

acquireSharedLock();

Expand Down Expand Up @@ -196,6 +199,9 @@ public int decompressDirectByteBuffer(ByteBuffer dstBuff, int dstOffset, int dst
* @return the number of bytes decompressed into destination buffer (originalSize)
*/
public int decompressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize) {
Objects.checkFromIndexSize(srcOffset, srcSize, srcBuff.length);
Objects.checkFromIndexSize(dstOffset, dstSize, dstBuff.length);

ensureOpen();
acquireSharedLock();

Expand Down

0 comments on commit 7fd6382

Please sign in to comment.