Skip to content

Commit 8c4a325

Browse files
Verify the entry type for ConstantValue attributes
1 parent 54dfa94 commit 8c4a325

File tree

1 file changed

+12
-0
lines changed
  • espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile

1 file changed

+12
-0
lines changed

espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/ClassfileParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,18 @@ private ParserField parseField(boolean isInterface) throws ValidationException {
18211821
if (constantValue.getConstantValueIndex() == 0) {
18221822
throw classFormatError("Invalid ConstantValue index");
18231823
}
1824+
PoolConstant entry = pool.at(constantValue.getConstantValueIndex(), "constant value index");
1825+
boolean isValid = switch (entry.tag()) {
1826+
case INTEGER -> Types.getJavaKind(descriptor).isStackInt();
1827+
case FLOAT -> descriptor == Type._float;
1828+
case LONG -> descriptor == Type._long;
1829+
case DOUBLE -> descriptor == Type._double;
1830+
case STRING -> descriptor == Type.java_lang_String;
1831+
default -> false;
1832+
};
1833+
if (!isValid) {
1834+
throw classFormatError("Invalid ConstantValue index entry type");
1835+
}
18241836
} else if (attributeName.equals(Name.Synthetic)) {
18251837
fieldFlags |= ACC_SYNTHETIC;
18261838
fieldAttributes[i] = new Attribute(attributeName, null);

0 commit comments

Comments
 (0)