@@ -506,11 +506,15 @@ private void DecodePixelData<TPixel>(DeflateStream compressedStream, ImageFrame<
506506 while ( this . currentRow < this . header . Height )
507507 {
508508 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 )
512510 {
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 ;
514518 }
515519
516520 this . currentRowBytesRead = 0 ;
@@ -577,11 +581,15 @@ private void DecodeInterlacedPixelData<TPixel>(DeflateStream compressedStream, I
577581
578582 while ( this . currentRow < this . header . Height )
579583 {
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 )
583585 {
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 ;
585593 }
586594
587595 this . currentRowBytesRead = 0 ;
0 commit comments