Skip to content

Commit 2e1f627

Browse files
authored
Merge pull request #1525 from lesserwhirls/gh-1523
Fix integer overflow for inflate
2 parents 7208de2 + c5d62c5 commit 2e1f627

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

cdm/core/src/main/java/ucar/nc2/filter/Deflate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public byte[] encode(byte[] dataIn) throws IOException {
6969

7070
@Override
7171
public byte[] decode(byte[] dataIn) throws IOException {
72-
int len = Math.min(8 * dataIn.length, MAX_ARRAY_LEN);
72+
long approxLen = (long) 8 * dataIn.length;
73+
int len = approxLen > MAX_ARRAY_LEN ? MAX_ARRAY_LEN : (int) approxLen;
7374
try (ByteArrayInputStream in = new ByteArrayInputStream(dataIn);
7475
InflaterInputStream iis = new InflaterInputStream(in, new Inflater(), dataIn.length);
7576
ByteArrayOutputStream os = new ByteArrayOutputStream(len)) {

cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5tiledLayoutBB.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ private byte[] inflate(byte[] compressed) throws IOException {
252252

253253
java.util.zip.InflaterInputStream inflatestream =
254254
new java.util.zip.InflaterInputStream(in, inflater, inflatebuffersize);
255-
int len = Math.min(8 * compressed.length, MAX_ARRAY_LEN);
255+
long approxLen = (long) 8 * compressed.length;
256+
int len = approxLen > MAX_ARRAY_LEN ? MAX_ARRAY_LEN : (int) approxLen;
256257
ByteArrayOutputStream out = new ByteArrayOutputStream(len); // Fixes KXL-349288
257258
IO.copyB(inflatestream, out, len);
258259

0 commit comments

Comments
 (0)