Combine next char checks; class names may not have L! validate prims.

I think something else in narya must be stripping off the "L;" ..?
This commit is contained in:
Ray J. Greenwell
2026-03-20 16:20:10 -07:00
parent 6180dc265c
commit c874221e62
@@ -278,28 +278,29 @@ public class ObjectInputStream extends DataInputStream
protected void validateClassPrefix (short code, String cname)
throws IOException
{
// strip array prefixes to get the component type descriptor
int start = 0, end = cname.length();
while (start < end && cname.charAt(start) == '[') {
start++;
}
if (start < end) {
switch (cname.charAt(start)) {
default: break;
case 'I': case 'Z': case 'B': case 'S': case 'C': case 'J': case 'F': case 'D':
return; // primitive descriptors (I, Z, B, S, C, J, F, D) are always safe
for (int start = 0, end = cname.length(); start < end; ++start) {
char c = cname.charAt(start);
if (c == '[') continue; // continue the loop to step past array markers
case 'L':
if (cname.endsWith(";")) {
// extract the class name from "Lcom.threerings.Foo;"
String className = cname.substring(start + 1, end - 1);
// if it's a single character do a quick check:
if (start == end - 1) {
switch (c) {
case 'I': case 'Z': case 'B': case 'S': case 'C': case 'J': case 'F': case 'D': return;
}
} else {
// This is annoying: Something else is pre-stripping the L if not in an array?
if (c == 'L' && cname.endsWith(";")) {
++start;
--end;
}
String className = cname.substring(start, end);
for (String prefix : _allowedPrefixes) {
if (className.startsWith(prefix)) {
return;
}
}
}
}
break; // if we didn't see a [, we're done processing
}
log.warning("Blocked deserialization of non-whitelisted class",