This is an automated email from the ASF dual-hosted git repository.

garydgregory 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 68628e6a Read multianewarray dimensions as unsigned byte (#504)
68628e6a is described below

commit 68628e6a5c6c5c5d4e8666897ae071f8e468c68e
Author: Dexter.k <[email protected]>
AuthorDate: Wed Jun 17 11:45:19 2026 +0000

    Read multianewarray dimensions as unsigned byte (#504)
---
 .../org/apache/bcel/generic/MULTIANEWARRAY.java    |  2 +-
 .../apache/bcel/generic/MULTIANEWARRAYTest.java    | 42 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/bcel/generic/MULTIANEWARRAY.java 
b/src/main/java/org/apache/bcel/generic/MULTIANEWARRAY.java
index 5c289976..bdc2f027 100644
--- a/src/main/java/org/apache/bcel/generic/MULTIANEWARRAY.java
+++ b/src/main/java/org/apache/bcel/generic/MULTIANEWARRAY.java
@@ -125,7 +125,7 @@ public class MULTIANEWARRAY extends CPInstruction 
implements LoadClass, Allocati
     @Override
     protected void initFromFile(final ByteSequence bytes, final boolean wide) 
throws IOException {
         super.initFromFile(bytes, wide);
-        dimensions = bytes.readByte();
+        dimensions = (short) bytes.readUnsignedByte();
         super.setLength(4);
     }
 
diff --git a/src/test/java/org/apache/bcel/generic/MULTIANEWARRAYTest.java 
b/src/test/java/org/apache/bcel/generic/MULTIANEWARRAYTest.java
new file mode 100644
index 00000000..c991319b
--- /dev/null
+++ b/src/test/java/org/apache/bcel/generic/MULTIANEWARRAYTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ *   https://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.generic;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.util.ByteSequence;
+import org.junit.jupiter.api.Test;
+
+class MULTIANEWARRAYTest {
+
+    /**
+     * The {@code dimensions} operand of {@code multianewarray} is an unsigned 
byte (1-255), so a value above 127 must not be
+     * read as a negative number.
+     */
+    @Test
+    void testInitFromFileReadsDimensionsUnsigned() throws Exception {
+        // multianewarray, index 0x0005, dimensions 0xC8 (200)
+        final byte[] code = {(byte) Const.MULTIANEWARRAY, 0x00, 0x05, (byte) 
0xC8};
+        try (ByteSequence bytes = new ByteSequence(code)) {
+            final MULTIANEWARRAY instruction = (MULTIANEWARRAY) 
Instruction.readInstruction(bytes);
+            assertEquals(200, instruction.getDimensions());
+        }
+    }
+}

Reply via email to