Skip to content

Commit c1a9db3

Browse files
alerisAdrian Tosca
andauthored
Fix bug for when the first char is non-ascii char (#5)
Crashes with: Index 258 out of bounds for length 256 java.lang.ArrayIndexOutOfBoundsException: Index 258 out of bounds for length 256 This changes the check for first char with a direct range check. Co-authored-by: Adrian Tosca <atosca@adobe.com>
1 parent 791ad7b commit c1a9db3

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lib/src/main/java/de/fxlae/typeid/lib/TypeIdLib.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ private static String validateSuffixOnInput(final String input, final int separa
204204
return "Suffix with illegal length, must be " + SUFFIX_LENGTH;
205205
}
206206

207-
if (((SUFFIX_LOOKUP[input.charAt(start)] >>> 3) & 0x3) > 0) {
207+
final char firstChar = input.charAt(start);
208+
if ((firstChar < '0' || firstChar > '7')) {
208209
return "Illegal leftmost suffix character, must be one of [01234567]";
209210
}
210211

lib/src/test/java/de/fxlae/typeid/lib/TypeIdLibTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
3636
"",
3737
"_",
3838
"someprefix_", // no suffix at all
39-
"_01h455vb4pex5vsknk084sn02q", // suffix only, but with preceding underscore
39+
"_01h455vb4pex5vsknk084sn02q", // suffix only, but with the preceding underscore
4040
"__01h455vb4pex5vsknk084sn02q", // prefix is single underscore
4141
"_someprefix_01h455vb4pex5vsknk084sn02q", // prefix starts with underscore
4242
"someprefix__01h455vb4pex5vsknk084sn02q", // prefix ends with underscore
4343
"_someprefix__01h455vb4pex5vsknk084sn02q", // prefix starts and ends with underscore
4444
"sömeprefix_01h455vb4pex5vsknk084sn02q", // prefix with 'ö'
4545
"someprefix_01h455öb4pex5vsknk084sn02q", // suffix with 'ö'
46+
"someprefix_Ă01h455b4pex5vsknk084sn02q", // suffix with 'Ă' (> ascii 255) as first char
4647
"sOmeprefix_01h455vb4pex5vsknk084sn02q", // prefix with 'O'
4748
"someprefix_01h455Vb4pex5vsknk084sn02q", // suffix with 'V'
4849
"someprefix_01h455lb4pex5vsknk084sn02q", // suffix with 'l'
@@ -105,4 +106,4 @@ void parseInvalidAgainstSpec(String name, String typeIdAsString, String descript
105106

106107
record Tuple<A, B>(A first, B second) {
107108
}
108-
}
109+
}

0 commit comments

Comments
 (0)