Skip to content

Commit

Permalink
Ignore bogus type annotation entries - Fixes #93
Browse files Browse the repository at this point in the history
  • Loading branch information
n1hility committed Nov 11, 2020
1 parent 7f2c075 commit 0860953
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,12 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati
}
case 0x10: // CLASS_EXTENDS
{
if (!(target instanceof ClassInfo)) {
throw new IllegalStateException("Class extends type annotation appeared on a non class target");
int position = data.readUnsignedShort();

// Skip invalid usage (observed bad bytecode on method attributes)
if (target instanceof ClassInfo) {
typeTarget = new ClassExtendsTypeTarget((ClassInfo)target, position);
}
typeTarget = new ClassExtendsTypeTarget((ClassInfo)target, data.readUnsignedShort());
break;
}
case 0x11: // CLASS_TYPE_PARAMETER_BOUND
Expand All @@ -553,18 +555,18 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati
break;
case 0x16: // METHOD_FORMAL_PARAMETER
{
if (!(target instanceof MethodInfo)) {
throw new IllegalStateException("Method parameter type annotation appeared on a non-method target");
int position = data.readUnsignedByte();
if (target instanceof MethodInfo) {
typeTarget = new MethodParameterTypeTarget((MethodInfo)target, position);
}
typeTarget = new MethodParameterTypeTarget((MethodInfo)target, data.readUnsignedByte());
break;
}
case 0x17: // THROWS
{
if (!(target instanceof MethodInfo)) {
throw new IllegalStateException("Throws type annotation appeared on a non-method target");
int position = data.readUnsignedShort();
if (target instanceof MethodInfo) {
typeTarget = new ThrowsTypeTarget((MethodInfo) target, position);
}
typeTarget = new ThrowsTypeTarget((MethodInfo) target, data.readUnsignedShort());
break;
}
// Skip code attribute values, which shouldn't be present
Expand Down Expand Up @@ -595,6 +597,10 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati
}

if (typeTarget == null) {
skipTargetPath(data);
// eat
// TODO - introduce an allocation free annotation skip
processAnnotation(data, null);
return null;
}

Expand Down Expand Up @@ -1055,6 +1061,11 @@ private ArrayList<PathElement> processTargetPath(DataInputStream data, BooleanHo
return elements;
}

private void skipTargetPath(DataInputStream data) throws IOException {
int numElements = data.readUnsignedByte();
skipFully(data, numElements * 2);
}

private void processExceptions(DataInputStream data, MethodInfo target) throws IOException {
int numExceptions = data.readUnsignedShort();

Expand Down

0 comments on commit 0860953

Please sign in to comment.