Commit 91291d09 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch '317875-fix-infinite-loop-with-invalid-type-arguments' into 'master'

Fix infinite loop with invalid arguments.

Closes #317875

See merge request !267
parents 358b0015 4ff64ff4
......@@ -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;
}
......
......@@ -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"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment