@@ -361,9 +361,7 @@ void consumeTokenString(int cc) throws JsonParserException {
361361 // Make sure that there's enough chars for a \\uXXXX escape
362362 if (buffer [index ] == 'u' && n < MAX_ESCAPE ) {
363363 index = bufferLength ; // Reset index to last valid location
364- throw createParseException (null ,
365- "EOF encountered in the middle of a string escape" ,
366- false );
364+ throw createParseException (null , "EOF encountered in the middle of a string escape" , false );
367365 }
368366 }
369367 char escape = buffer [index ++];
@@ -420,9 +418,7 @@ void consumeTokenString(int cc) throws JsonParserException {
420418
421419 if (index > bufferLength ) {
422420 index = bufferLength ; // Reset index to last valid location
423- throw createParseException (null ,
424- "EOF encountered in the middle of a string escape" ,
425- false );
421+ throw createParseException (null , "EOF encountered in the middle of a string escape" , false );
426422 }
427423 }
428424 }
@@ -439,8 +435,9 @@ void consumeTokenSemiString() throws JsonParserException {
439435 for (int i = 0 ; i < n ; i ++) {
440436 char c = stringChar ();
441437 if (isWhitespace (c ) || c == ':' ) {
442- fixupAfterRawBufferRead ();
438+ // Use the index before we fixup
443439 reusableBuffer .append (buffer , index - i - 1 , i );
440+ fixupAfterRawBufferRead ();
444441 return ;
445442 }
446443 if (c == '\\' || (utf8 && (c & 0x80 ) != 0 )) {
@@ -487,6 +484,17 @@ void consumeTokenSemiString() throws JsonParserException {
487484 case ',' :
488485 throw createParseException (null , "Invalid character in semi-string: " + c , false );
489486 case '\\' :
487+ // Ensure that we have at least MAX_ESCAPE here in the buffer
488+ if (end - index < MAX_ESCAPE ) {
489+ // Re-adjust the buffer end, unlikely path
490+ n = ensureBuffer (MAX_ESCAPE );
491+ end = index + n ;
492+ // Make sure that there's enough chars for a \\uXXXX escape
493+ if (buffer [index ] == 'u' && n < MAX_ESCAPE ) {
494+ index = bufferLength ; // Reset index to last valid location
495+ throw createParseException (null , "EOF encountered in the middle of a string escape" , false );
496+ }
497+ }
490498 char escape = buffer [index ++];
491499 switch (escape ) {
492500 case 'b' :
@@ -540,9 +548,7 @@ void consumeTokenSemiString() throws JsonParserException {
540548
541549 if (index > bufferLength ) {
542550 index = bufferLength ; // Reset index to last valid location
543- throw createParseException (null ,
544- "EOF encountered in the middle of a string escape" ,
545- false );
551+ throw createParseException (null , "EOF encountered in the middle of a string escape" , false );
546552 }
547553 }
548554 }
0 commit comments