Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -140,7 +140,7 @@ public override int Read(byte[] buffer, int offset, int count)

offset += bytesRead;

if (offset >= length)
if (offset >= length || offset >= count)
{
return bytesRead;
}
Expand Down Expand Up @@ -249,4 +249,4 @@ private void InitializeInflateStream()
this.compressedStream = new DeflateStream(this, CompressionMode.Decompress, true);
}
}
}
}
7 changes: 4 additions & 3 deletions tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

// ReSharper disable InconsistentNaming
Expand Down Expand Up @@ -42,7 +42,8 @@ public partial class PngDecoderTests
TestImages.Png.Rgb24BppTrans,
TestImages.Png.GrayAlpha8Bit,
TestImages.Png.Gray1BitTrans,
TestImages.Png.Bad.ZlibOverflow
TestImages.Png.Bad.ZlibOverflow,
TestImages.Png.Bad.ZlibOverflow2
};

public static readonly string[] TestImages48Bpp =
Expand Down Expand Up @@ -294,4 +295,4 @@ public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolut
}
}
}
}
}
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static class Bad
public const string ChunkLength2 = "Png/chunklength2.png";
public const string CorruptedChunk = "Png/big-corrupted-chunk.png";
public const string ZlibOverflow = "Png/zlib-overflow.png";
public const string ZlibOverflow2 = "Png/zlib-overflow2.png";
}

public static readonly string[] All =
Expand Down
Binary file added tests/Images/Input/Png/zlib-overflow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.