diff --git a/asm/src/main/java/org/objectweb/asm/Type.java b/asm/src/main/java/org/objectweb/asm/Type.java index 8734bd00421f445a8a2c2505206e0bfedc69a27c..01c68b460fe026c9fc6286d05e8be325f9e2dc39 100644 --- a/asm/src/main/java/org/objectweb/asm/Type.java +++ b/asm/src/main/java/org/objectweb/asm/Type.java @@ -305,7 +305,8 @@ public final class Type { } if (methodDescriptor.charAt(currentOffset++) == 'L') { // Skip the argument descriptor content. - currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1; + int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); + currentOffset = Math.max(currentOffset, semiColumnOffset + 1); } ++numArgumentTypes; } @@ -323,7 +324,8 @@ public final class Type { } if (methodDescriptor.charAt(currentOffset++) == 'L') { // Skip the argument descriptor content. - currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1; + int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); + currentOffset = Math.max(currentOffset, semiColumnOffset + 1); } argumentTypes[currentArgumentTypeIndex++] = getTypeInternal(methodDescriptor, currentArgumentTypeOffset, currentOffset); @@ -393,7 +395,8 @@ public final class Type { } if (methodDescriptor.charAt(currentOffset++) == 'L') { // Skip the argument descriptor content. - currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1; + int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); + currentOffset = Math.max(currentOffset, semiColumnOffset + 1); } } return currentOffset + 1; @@ -737,7 +740,8 @@ public final class Type { } if (methodDescriptor.charAt(currentOffset++) == 'L') { // Skip the argument descriptor content. - currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1; + int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); + currentOffset = Math.max(currentOffset, semiColumnOffset + 1); } argumentsSize += 1; } diff --git a/asm/src/test/java/org/objectweb/asm/TypeTest.java b/asm/src/test/java/org/objectweb/asm/TypeTest.java index 15143549847e15aebace0e307931e15f9c046c18..ecf1f071a5d3e1a72c8b4f3621bfd56fee8ce2ba 100644 --- a/asm/src/test/java/org/objectweb/asm/TypeTest.java +++ b/asm/src/test/java/org/objectweb/asm/TypeTest.java @@ -31,7 +31,9 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; +import java.time.Duration; import java.util.Arrays; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; @@ -175,6 +177,14 @@ public class TypeTest implements Opcodes { assertEquals(returnType, methodType.getReturnType()); } + @Test + public void testGetArgumentTypesInvalidMethodDescriptor() { + Executable getArgumentTypes = () -> Type.getArgumentTypes("(Ljava/lang/String"); + + assertTimeoutPreemptively( + Duration.ofMillis(100), () -> assertThrows(RuntimeException.class, getArgumentTypes)); + } + @Test public void testGetReturnTypeFromDescriptor() { assertEquals(Type.INT_TYPE, Type.getReturnType("()I"));