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
commit 939f0eba29d3308871adc2948a6ece803c93eece Author: Gary David Gregory (Code signing key) <[email protected]> AuthorDate: Tue Nov 22 07:45:43 2022 -0500 org.apache.bcel.classfile.StackMap constructors now throw ClassFormatException on invalid input --- src/main/java/org/apache/bcel/classfile/StackMap.java | 10 ++++++---- .../java/org/apache/bcel/classfile/StackMapEntry.java | 17 +++++++---------- .../java/org/apache/bcel/classfile/StackMapType.java | 2 ++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/bcel/classfile/StackMap.java b/src/main/java/org/apache/bcel/classfile/StackMap.java index 30f38034..80f2d2a7 100644 --- a/src/main/java/org/apache/bcel/classfile/StackMap.java +++ b/src/main/java/org/apache/bcel/classfile/StackMap.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Arrays; import org.apache.bcel.Const; +import org.apache.bcel.util.Args; /** * This class represents a stack map attribute used for preverification of Java classes for the @@ -73,9 +74,10 @@ public final class StackMap extends Attribute { * * @param constantPool Array of constants */ - public StackMap(final int nameIndex, final int length, final StackMapEntry[] map, final ConstantPool constantPool) { + public StackMap(final int nameIndex, final int length, final StackMapEntry[] table, final ConstantPool constantPool) { super(Const.ATTR_STACK_MAP, nameIndex, length, constantPool); - this.table = map; + this.table = table != null ? table : StackMapEntry.EMPTY_ARRAY; + Args.requireU2(this.table.length, "table.length"); } /** @@ -117,7 +119,7 @@ public final class StackMap extends Attribute { } public int getMapLength() { - return table == null ? 0 : table.length; + return table.length; } /** @@ -131,7 +133,7 @@ public final class StackMap extends Attribute { * @param table Array of stack map entries */ public void setStackMap(final StackMapEntry[] table) { - this.table = table; + this.table = table != null ? table : StackMapEntry.EMPTY_ARRAY; int len = 2; // Length of 'number_of_entries' field prior to the array of stack maps for (final StackMapEntry element : table) { len += element.getMapEntrySize(); diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java index 9da003db..0eed5838 100644 --- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java +++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java @@ -46,10 +46,7 @@ import org.apache.bcel.Const; */ public final class StackMapEntry implements Node, Cloneable { - /** - * Empty array. - */ - private static final StackMapType[] EMPTY_STACK_MAP_TYPE_ARRAY = {}; + static final StackMapEntry[] EMPTY_ARRAY = {}; private int frameType; private int byteCodeOffset; @@ -118,8 +115,8 @@ public final class StackMapEntry implements Node, Cloneable { public StackMapEntry(final int byteCodeOffset, final int numberOfLocals, final StackMapType[] typesOfLocals, final int numberOfStackItems, final StackMapType[] typesOfStackItems, final ConstantPool constantPool) { this.byteCodeOffset = byteCodeOffset; - this.typesOfLocals = typesOfLocals != null ? typesOfLocals : EMPTY_STACK_MAP_TYPE_ARRAY; - this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : EMPTY_STACK_MAP_TYPE_ARRAY; + this.typesOfLocals = typesOfLocals != null ? typesOfLocals : StackMapType.EMPTY_ARRAY; + this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : StackMapType.EMPTY_ARRAY; this.constantPool = constantPool; if (numberOfLocals < 0) { throw new IllegalArgumentException("numberOfLocals < 0"); @@ -142,8 +139,8 @@ public final class StackMapEntry implements Node, Cloneable { final ConstantPool constantPool) { this.frameType = tag; this.byteCodeOffset = byteCodeOffset; - this.typesOfLocals = typesOfLocals != null ? typesOfLocals : EMPTY_STACK_MAP_TYPE_ARRAY; - this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : EMPTY_STACK_MAP_TYPE_ARRAY; + this.typesOfLocals = typesOfLocals != null ? typesOfLocals : StackMapType.EMPTY_ARRAY; + this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : StackMapType.EMPTY_ARRAY; this.constantPool = constantPool; } @@ -350,11 +347,11 @@ public final class StackMapEntry implements Node, Cloneable { } public void setTypesOfLocals(final StackMapType[] types) { - typesOfLocals = types != null ? types : EMPTY_STACK_MAP_TYPE_ARRAY; + typesOfLocals = types != null ? types : StackMapType.EMPTY_ARRAY; } public void setTypesOfStackItems(final StackMapType[] types) { - typesOfStackItems = types != null ? types : EMPTY_STACK_MAP_TYPE_ARRAY; + typesOfStackItems = types != null ? types : StackMapType.EMPTY_ARRAY; } /** diff --git a/src/main/java/org/apache/bcel/classfile/StackMapType.java b/src/main/java/org/apache/bcel/classfile/StackMapType.java index 438fa5df..c9d6fdc4 100644 --- a/src/main/java/org/apache/bcel/classfile/StackMapType.java +++ b/src/main/java/org/apache/bcel/classfile/StackMapType.java @@ -31,6 +31,8 @@ import org.apache.bcel.Const; */ public final class StackMapType implements Cloneable { + static final StackMapType[] EMPTY_ARRAY = {}; + private byte type; private int index = -1; // Index to CONSTANT_Class or offset private ConstantPool constantPool;
