Skip to content

Commit

Permalink
reduce max type length
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Feb 3, 2025
1 parent d60ea97 commit d653afa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/esaulpaugh/headlong/abi/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class TypeFactory {
UnitType.initInstances(); // initialize type maps
}

private static final int MAX_LENGTH_CHARS = 2_000;
private static final int MAX_LENGTH_CHARS = 1_600;

private TypeFactory() {}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/esaulpaugh/headlong/abi/TupleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void testParseBadFixed() throws Throwable {

@Test
public void testLengthLimit() throws Throwable {
final byte[] typeBytes = new byte[2002];
final byte[] typeBytes = new byte[1602];
final int midpoint = typeBytes.length / 2;
int i = 0;
while (i < midpoint) {
Expand All @@ -566,19 +566,19 @@ public void testLengthLimit() throws Throwable {
typeBytes[i++] = ')';
}
final String ascii = Strings.encode(typeBytes, Strings.ASCII);
assertThrown(IllegalArgumentException.class, "type length exceeds maximum: 2002 > 2000" , () -> TupleType.parse(ascii));
assertThrown(IllegalArgumentException.class, "type length exceeds maximum: 1602 > 1600" , () -> TupleType.parse(ascii));

final Random r = TestUtils.seededRandom();
final StringBuilder sb = new StringBuilder(r.nextBoolean() ? "string" : "bool");
for (int j = 0; j < 1_000; j++) {
for (int j = 0; j < 800; j++) {
if (r.nextBoolean()) {
sb.append("[]");
} else {
sb.append('[').append(r.nextInt(100)).append(']');
}
}
final String arrType = sb.toString();
assertThrown(IllegalArgumentException.class, "type length exceeds maximum: " + arrType.length() + " > 2000" , () -> TypeFactory.create(arrType));
assertThrown(IllegalArgumentException.class, "type length exceeds maximum: " + arrType.length() + " > 1600" , () -> TypeFactory.create(arrType));
}

@Test
Expand Down

0 comments on commit d653afa

Please sign in to comment.