You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/22 12:52:40 UTC

[commons-bcel] 06/11: org.apache.bcel.classfile.NestMembers constructors now throw ClassFormatException on invalid input

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 d7f558d934101b47274cdb6dd45c07141af97289
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Mon Nov 21 16:48:29 2022 -0500

    org.apache.bcel.classfile.NestMembers constructors now throw
    ClassFormatException on invalid input
---
 src/changes/changes.xml                                  | 1 +
 src/main/java/org/apache/bcel/classfile/NestMembers.java | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 541d5946..f6ca3f00 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -109,6 +109,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.ModuleMainClass constructors now throw ClassFormatException on invalid input.</action>
       <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.ModulePackages constructors now throw ClassFormatException on invalid input.</action>
       <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.NestHost constructors now throw ClassFormatException on invalid input.</action>
+      <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.NestMembers constructors now throw ClassFormatException on invalid input.</action>
       <!-- UPDATE -->
       <action                  type="update" dev="ggregory" due-to="Gary Gregory">Bump spotbugs-maven-plugin from 4.7.2.2 to 4.7.3.0 #167.</action>
       <action                  type="update" dev="ggregory" due-to="Dependabot">Bump jmh.version from 1.35 to 1.36 #170.</action>
diff --git a/src/main/java/org/apache/bcel/classfile/NestMembers.java b/src/main/java/org/apache/bcel/classfile/NestMembers.java
index 376a6a5b..38fb944c 100644
--- a/src/main/java/org/apache/bcel/classfile/NestMembers.java
+++ b/src/main/java/org/apache/bcel/classfile/NestMembers.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
 import org.apache.commons.lang3.ArrayUtils;
 
 /**
@@ -63,6 +64,7 @@ public final class NestMembers extends Attribute {
     public NestMembers(final int nameIndex, final int length, final int[] classes, final ConstantPool constantPool) {
         super(Const.ATTR_NEST_MEMBERS, nameIndex, length, constantPool);
         this.classes = classes != null ? classes : ArrayUtils.EMPTY_INT_ARRAY;
+        Args.requireU2(this.classes.length, "classes.length");
     }
 
     /**
@@ -90,7 +92,7 @@ public final class NestMembers extends Attribute {
     @Override
     public Attribute copy(final ConstantPool constantPool) {
         final NestMembers c = (NestMembers) clone();
-        if (classes != null) {
+        if (classes.length > 0) {
             c.classes = classes.clone();
         }
         c.setConstantPool(constantPool);
@@ -132,7 +134,7 @@ public final class NestMembers extends Attribute {
      * @return Length of classes table.
      */
     public int getNumberClasses() {
-        return classes == null ? 0 : classes.length;
+        return classes.length;
     }
 
     /**