@@ -506,11 +506,15 @@ private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<
506
506
while ( this . currentRow < this . header . Height )
507
507
{
508
508
Span < byte > scanlineSpan = this . scanline . GetSpan ( ) ;
509
- int bytesRead = compressedStream . Read ( scanlineSpan , this . currentRowBytesRead , this . bytesPerScanline - this . currentRowBytesRead ) ;
510
- this . currentRowBytesRead += bytesRead ;
511
- if ( this . currentRowBytesRead < this . bytesPerScanline )
509
+ while ( this . currentRowBytesRead < this . bytesPerScanline )
512
510
{
513
- return ;
511
+ int bytesRead = compressedStream . Read ( scanlineSpan , this . currentRowBytesRead , this . bytesPerScanline - this . currentRowBytesRead ) ;
512
+ if ( bytesRead <= 0 )
513
+ {
514
+ return ;
515
+ }
516
+
517
+ this . currentRowBytesRead += bytesRead ;
514
518
}
515
519
516
520
this . currentRowBytesRead = 0 ;
@@ -577,11 +581,15 @@ private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, I
577
581
578
582
while ( this . currentRow < this . header . Height )
579
583
{
580
- int bytesRead = compressedStream . Read ( this . scanline . GetSpan ( ) , this . currentRowBytesRead , bytesPerInterlaceScanline - this . currentRowBytesRead ) ;
581
- this . currentRowBytesRead += bytesRead ;
582
- if ( this . currentRowBytesRead < bytesPerInterlaceScanline )
584
+ while ( this . currentRowBytesRead < bytesPerInterlaceScanline )
583
585
{
584
- return ;
586
+ int bytesRead = compressedStream . Read ( this . scanline . GetSpan ( ) , this . currentRowBytesRead , bytesPerInterlaceScanline - this . currentRowBytesRead ) ;
587
+ if ( bytesRead <= 0 )
588
+ {
589
+ return ;
590
+ }
591
+
592
+ this . currentRowBytesRead += bytesRead ;
585
593
}
586
594
587
595
this . currentRowBytesRead = 0 ;
0 commit comments