Skip to content

Commit d4bdb6c

Browse files
committed
Better memory guard
1 parent 17d6ca5 commit d4bdb6c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/LookupSwitchForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setByteCodeOperands(final ByteCode byteCode, final OperandManager op
4646
final int caseCount = operandManager.nextCaseCount();
4747
final int defaultPc = operandManager.nextLabel();
4848
// Check all at once here for all arrays in this method to account for failures seen in GH CI.
49-
Pack200Exception.checkIntArray(caseCount * 5); // yeah, might overflow.
49+
Pack200Exception.checkIntArray(caseCount * 8); // yeah, might overflow.
5050
final int[] caseValues = new int[Pack200Exception.checkIntArray(caseCount)];
5151
Arrays.setAll(caseValues, i -> operandManager.nextCaseValues());
5252
final int[] casePcs = new int[Pack200Exception.checkIntArray(caseCount)];

src/main/java/org/apache/commons/compress/harmony/unpack200/bytecode/forms/TableSwitchForm.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public void setByteCodeOperands(final ByteCode byteCode, final OperandManager op
5252
final int caseCount = operandManager.nextCaseCount();
5353
final int defaultPc = operandManager.nextLabel();
5454
final int caseValue = operandManager.nextCaseValues();
55+
// Check all at once here for all arrays in this method to account for failures seen in GH CI.
56+
Pack200Exception.checkIntArray(caseCount * 6); // yeah, might overflow.
5557
final int[] casePcs = new int[Pack200Exception.checkIntArray(caseCount)];
5658
Arrays.setAll(casePcs, i -> operandManager.nextLabel());
5759
final int[] labelsArray = new int[Pack200Exception.checkIntArray(caseCount + 1)];
@@ -99,7 +101,7 @@ public void setByteCodeOperands(final ByteCode byteCode, final OperandManager op
99101
rewriteIndex += 4;
100102
// jump offsets
101103
// The case_pcs will get overwritten by fixUpByteCodeTargets
102-
Arrays.fill(newRewrite, rewriteIndex, rewriteIndex + (caseCount * 4), -1);
104+
Arrays.fill(newRewrite, rewriteIndex, rewriteIndex + caseCount * 4, -1);
103105
byteCode.setRewrite(newRewrite);
104106
}
105107
}

0 commit comments

Comments
 (0)