This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new 859578ef [BCEL-367] Fixes java.lang.IndexOutOfBoundsException for
ATHROW on empty stack (#223)
859578ef is described below
commit 859578ef71e91f64ef4536ca407af359582caa1c
Author: katherine-hough <[email protected]>
AuthorDate: Sat Jun 17 06:39:19 2023 -0400
[BCEL-367] Fixes java.lang.IndexOutOfBoundsException for ATHROW on empty
stack (#223)
* * Fixed issue where a java.lang.IndexOutOfBoundsException is thrown when
performing verification pass 3B if the stack is empty before the ATHROW
instruction.
* Added previously failing test case demonstrating issue where a
java.lang.IndexOutOfBoundsException is thrown when performing verification pass
3B if the stack is empty before the ATHROW instruction.
* End file with empty line
* End file with empty line
* Format and message text
* Use final and format
---------
Co-authored-by: Gary Gregory <[email protected]>
---
src/main/java/org/apache/bcel/generic/ATHROW.java | 3 +-
.../bcel/verifier/VerifierThrowTestCase.java | 31 ++++++++++++++++
.../bcel/verifier/tests/TestThrow01Creator.java | 43 ++++++++++++++++++++++
3 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/generic/ATHROW.java
b/src/main/java/org/apache/bcel/generic/ATHROW.java
index 3d774f41..10c3096b 100644
--- a/src/main/java/org/apache/bcel/generic/ATHROW.java
+++ b/src/main/java/org/apache/bcel/generic/ATHROW.java
@@ -25,7 +25,7 @@ import org.apache.bcel.ExceptionConst;
* Stack: ..., objectref -> objectref
* </PRE>
*/
-public class ATHROW extends Instruction implements UnconditionalBranch,
ExceptionThrower {
+public class ATHROW extends Instruction implements UnconditionalBranch,
ExceptionThrower, StackConsumer {
/**
* Throw exception
@@ -44,6 +44,7 @@ public class ATHROW extends Instruction implements
UnconditionalBranch, Exceptio
public void accept(final Visitor v) {
v.visitUnconditionalBranch(this);
v.visitExceptionThrower(this);
+ v.visitStackConsumer(this);
v.visitATHROW(this);
}
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierThrowTestCase.java
b/src/test/java/org/apache/bcel/verifier/VerifierThrowTestCase.java
new file mode 100644
index 00000000..6ee75c11
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/VerifierThrowTestCase.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier;
+
+import org.apache.bcel.verifier.tests.TestThrow01Creator;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+public class VerifierThrowTestCase extends AbstractVerifierTestCase {
+ @Test
+ public void testThrowEmptyStack() throws IOException,
ClassNotFoundException {
+ new TestThrow01Creator().create();
+ assertVerifyRejected("TestThrow01", "Verification of a method with
ATHROW instruction on an empty stack must fail.");
+ }
+}
diff --git
a/src/test/java/org/apache/bcel/verifier/tests/TestThrow01Creator.java
b/src/test/java/org/apache/bcel/verifier/tests/TestThrow01Creator.java
new file mode 100644
index 00000000..13c7fc30
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestThrow01Creator.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.generic.*;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class TestThrow01Creator extends TestCreator {
+ private final ClassGen cg;
+
+ public TestThrow01Creator() {
+ cg = new ClassGen(TEST_PACKAGE + ".TestThrow01", "java.lang.Object",
"TestThrow01.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+ }
+
+ @Override
+ public void create(final OutputStream out) throws IOException {
+ final InstructionList il = new InstructionList();
+ final MethodGen method = new MethodGen(Const.ACC_STATIC, Type.VOID,
Type.NO_ARGS, new String[0], "b", cg.getClassName(), il, cg.getConstantPool());
+ il.append(InstructionConst.getInstruction(Const.ATHROW));
+ method.setMaxStack();
+ method.setMaxLocals();
+ cg.addMethod(method.getMethod());
+ il.dispose();
+ cg.getJavaClass().dump(out);
+ }
+}