Gracefully handle string value size exceeding 65535 bytes (#11750)

This commit is contained in:
Cardillan
2026-03-12 00:09:05 +01:00
committed by GitHub
parent b3561933f7
commit 6cc7ea5e57

View File

@@ -37,17 +37,22 @@ public class LParser{
String string(){
int from = pos;
int utflen = 0;
while(++pos < chars.length){
var c = chars[pos];
char c = chars[pos];
if(c == '\n'){
error("Missing closing quote \" before end of line.");
}else if(c == '"'){
break;
}
// See ByteBufferOutput.writeUTF()
utflen += c != 0 && c <= 0x7F ? 1 : c <= 0x7FF ? 2 : 3;
}
if(pos >= chars.length || chars[pos] != '"') error("Missing closing quote \" before end of file.");
if(utflen > 65535) error("String value too long.");
return new String(chars, from, ++pos - from);
}