Skip to content

Commit 0ee5790

Browse files
committed
Add explicit check for well-formed array descriptor.
1 parent 5904a74 commit 0ee5790

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,13 @@ public Resolution describe(String name) {
587587
}
588588
if (arity > 0) {
589589
String primitiveName = PRIMITIVE_DESCRIPTORS.get(name);
590-
name = primitiveName == null
591-
? name.substring(1, name.length() - 1)
592-
: primitiveName;
590+
if (primitiveName != null) {
591+
name = primitiveName;
592+
} else if (name.startsWith("L") && name.endsWith(";")) {
593+
name = name.substring(1, name.length() - 1);
594+
} else {
595+
throw new IllegalArgumentException("Not a legitimate array type descriptor: " + name);
596+
}
593597
}
594598
TypeDescription typeDescription = PRIMITIVE_TYPES.get(name);
595599
Resolution resolution = typeDescription == null

byte-buddy-dep/src/test/java/net/bytebuddy/pool/TypePoolDefaultTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ public void testNameCannotContainSlash() throws Exception {
3333
typePool.describe("/");
3434
}
3535

36+
@Test(expected = IllegalArgumentException.class)
37+
public void testArrayNameMustBeDescriptorUnlessPrimitive() throws Exception {
38+
typePool.describe("[abc");
39+
}
40+
41+
@Test
42+
public void testPrimitiveType() throws Exception {
43+
assertThat(typePool.describe("int").resolve().represents(int.class), is(true));
44+
}
45+
46+
@Test
47+
public void testPrimitiveTypeArray() throws Exception {
48+
assertThat(typePool.describe("[I").resolve().represents(int[].class), is(true));
49+
}
50+
3651
@Test(expected = IllegalStateException.class)
3752
public void testCannotFindClass() throws Exception {
3853
TypePool.Resolution resolution = typePool.describe("foo");

0 commit comments

Comments
 (0)