From 086095399e73ef62652cc918959b9cdbedbd4ae8 Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Wed, 11 Nov 2020 14:48:13 -0600 Subject: [PATCH] Ignore bogus type annotation entries - Fixes #93 --- src/main/java/org/jboss/jandex/Indexer.java | 29 ++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jboss/jandex/Indexer.java b/src/main/java/org/jboss/jandex/Indexer.java index 95438432..e46461dc 100644 --- a/src/main/java/org/jboss/jandex/Indexer.java +++ b/src/main/java/org/jboss/jandex/Indexer.java @@ -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 @@ -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 @@ -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; } @@ -1055,6 +1061,11 @@ private ArrayList 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();