@@ -563,8 +563,17 @@ public void writeRaw(String text) throws IOException
563
563
}
564
564
565
565
@ Override
566
- public void writeRaw (String text , int start , int len ) throws IOException
566
+ public void writeRaw (String text , int offset , int len ) throws IOException
567
567
{
568
+ final int end = offset + len ;
569
+
570
+ // 03-Aug-2022, tatu: Maybe need to do bounds checks first (found by Fuzzer)
571
+ if ((offset < 0 ) || (len < 0 ) || end > text .length ()) {
572
+ _reportError (String .format (
573
+ "Invalid 'offset' (%d) and/or 'len' (%d) arguments for String of length %d" ,
574
+ offset , len , text .length ()));
575
+ }
576
+
568
577
// Nothing to check, can just output as is
569
578
int room = _outputEnd - _outputTail ;
570
579
@@ -574,10 +583,10 @@ public void writeRaw(String text, int start, int len) throws IOException
574
583
}
575
584
// But would it nicely fit in? If yes, it's easy
576
585
if (room >= len ) {
577
- text .getChars (start , start + len , _outputBuffer , _outputTail );
586
+ text .getChars (offset , end , _outputBuffer , _outputTail );
578
587
_outputTail += len ;
579
588
} else {
580
- writeRawLong (text .substring (start , start + len ));
589
+ writeRawLong (text .substring (offset , end ));
581
590
}
582
591
}
583
592
@@ -593,21 +602,28 @@ public void writeRaw(SerializableString text) throws IOException {
593
602
}
594
603
595
604
@ Override
596
- public void writeRaw (char [] text , int offset , int len ) throws IOException
605
+ public void writeRaw (char [] cbuf , int offset , int len ) throws IOException
597
606
{
607
+ // 03-Aug-2022, tatu: Maybe need to do bounds checks first (found by Fuzzer)
608
+ if ((offset < 0 ) || (len < 0 ) || (offset +len ) > cbuf .length ) {
609
+ _reportError (String .format (
610
+ "Invalid 'offset' (%d) and/or 'len' (%d) arguments for `char[]` of length %d" ,
611
+ offset , len , cbuf .length ));
612
+ }
613
+
598
614
// Only worth buffering if it's a short write?
599
615
if (len < SHORT_WRITE ) {
600
616
int room = _outputEnd - _outputTail ;
601
617
if (len > room ) {
602
618
_flushBuffer ();
603
619
}
604
- System .arraycopy (text , offset , _outputBuffer , _outputTail , len );
620
+ System .arraycopy (cbuf , offset , _outputBuffer , _outputTail , len );
605
621
_outputTail += len ;
606
622
return ;
607
623
}
608
624
// Otherwise, better just pass through:
609
625
_flushBuffer ();
610
- _writer .write (text , offset , len );
626
+ _writer .write (cbuf , offset , len );
611
627
}
612
628
613
629
@ Override
0 commit comments