Browse Source

Merge pull request #1707 from stephentoub/fixdsread

Fix a few uses of DeflateStream.Read
pull/1709/head
James Jackson-South 5 years ago
committed by GitHub
parent
commit
9baba86a3a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 13
      src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs

24
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -506,11 +506,15 @@ namespace SixLabors.ImageSharp.Formats.Png
while (this.currentRow < this.header.Height) while (this.currentRow < this.header.Height)
{ {
Span<byte> scanlineSpan = this.scanline.GetSpan(); Span<byte> scanlineSpan = this.scanline.GetSpan();
int bytesRead = compressedStream.Read(scanlineSpan, this.currentRowBytesRead, this.bytesPerScanline - this.currentRowBytesRead); while (this.currentRowBytesRead < this.bytesPerScanline)
this.currentRowBytesRead += bytesRead;
if (this.currentRowBytesRead < this.bytesPerScanline)
{ {
return; int bytesRead = compressedStream.Read(scanlineSpan, this.currentRowBytesRead, this.bytesPerScanline - this.currentRowBytesRead);
if (bytesRead <= 0)
{
return;
}
this.currentRowBytesRead += bytesRead;
} }
this.currentRowBytesRead = 0; this.currentRowBytesRead = 0;
@ -577,11 +581,15 @@ namespace SixLabors.ImageSharp.Formats.Png
while (this.currentRow < this.header.Height) while (this.currentRow < this.header.Height)
{ {
int bytesRead = compressedStream.Read(this.scanline.GetSpan(), this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead); while (this.currentRowBytesRead < bytesPerInterlaceScanline)
this.currentRowBytesRead += bytesRead;
if (this.currentRowBytesRead < bytesPerInterlaceScanline)
{ {
return; int bytesRead = compressedStream.Read(this.scanline.GetSpan(), this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead);
if (bytesRead <= 0)
{
return;
}
this.currentRowBytesRead += bytesRead;
} }
this.currentRowBytesRead = 0; this.currentRowBytesRead = 0;

13
src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs

@ -46,7 +46,18 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{ {
deframeStream.AllocateNewBytes(byteCount, true); deframeStream.AllocateNewBytes(byteCount, true);
DeflateStream dataStream = deframeStream.CompressedStream; DeflateStream dataStream = deframeStream.CompressedStream;
dataStream.Read(buffer, 0, buffer.Length);
int totalRead = 0;
while (totalRead < buffer.Length)
{
int bytesRead = dataStream.Read(buffer, totalRead, buffer.Length - totalRead);
if (bytesRead <= 0)
{
break;
}
totalRead += bytesRead;
}
} }
if (this.Predictor == TiffPredictor.Horizontal) if (this.Predictor == TiffPredictor.Horizontal)

Loading…
Cancel
Save