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/21 18:48:47 UTC
[commons-bcel] 02/02: org.apache.bcel.classfile.LineNumber 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 ce1450d8b0caed042f78218a29524283edfc0295
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Mon Nov 21 13:48:41 2022 -0500
org.apache.bcel.classfile.LineNumber constructors now throw
ClassFormatException on invalid input
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/LineNumber.java | 12 ++++++++----
src/main/java/org/apache/bcel/classfile/LineNumberTable.java | 4 +++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a27605ea..876c0384 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.CodeException constructors now throw ClassFormatException on invalid input.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.ExceptionTable constructors now throw ClassFormatException on invalid input.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.InnerClasses constructors now throw ClassFormatException on invalid input.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.LineNumber 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/LineNumber.java b/src/main/java/org/apache/bcel/classfile/LineNumber.java
index 0334d516..e5323146 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumber.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumber.java
@@ -20,6 +20,8 @@ import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
+import org.apache.bcel.util.Args;
+
/**
* This class represents a (PC offset, line number) pair, i.e., a line number in the source that corresponds to a
* relative address in the byte code. This is used for debugging purposes.
@@ -28,11 +30,13 @@ import java.io.IOException;
*/
public final class LineNumber implements Cloneable, Node {
+ static final LineNumber[] EMPTY_ARRAY = {};
+
/** Program Counter (PC) corresponds to line */
- private short startPc;
+ private int startPc;
/** number in source file */
- private short lineNumber;
+ private int lineNumber;
/**
* Construct object from file stream.
@@ -49,8 +53,8 @@ public final class LineNumber implements Cloneable, Node {
* @param lineNumber line number in source file
*/
public LineNumber(final int startPc, final int lineNumber) {
- this.startPc = (short) startPc;
- this.lineNumber = (short) lineNumber;
+ this.startPc = Args.requireU2(startPc, "startPc");
+ this.lineNumber = Args.requireU2(lineNumber, "lineNumber");
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
index cd481be2..961a16aa 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.stream.Stream;
import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
/**
* This class represents a table of line numbers for debugging purposes. This attribute is used by the <em>Code</em>
@@ -66,7 +67,8 @@ public final class LineNumberTable extends Attribute implements Iterable<LineNum
*/
public LineNumberTable(final int nameIndex, final int length, final LineNumber[] lineNumberTable, final ConstantPool constantPool) {
super(Const.ATTR_LINE_NUMBER_TABLE, nameIndex, length, constantPool);
- this.lineNumberTable = lineNumberTable;
+ this.lineNumberTable = lineNumberTable != null ? lineNumberTable : LineNumber.EMPTY_ARRAY;
+ Args.requireU2(this.lineNumberTable.length, "lineNumberTable.length");
}
/*