diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d9e0f1e08f..ec3ebfa1dc 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -68,7 +68,9 @@ jobs: steps: - name: Install libgdi+, which is required for tests running on ubuntu if: ${{ contains(matrix.options.os, 'ubuntu') }} - run: sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev + run: | + sudo apt-get update + sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev - name: Git Config shell: bash diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index db9aca0b08..de95bf01b2 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -18,7 +18,9 @@ jobs: steps: - name: Install libgdi+, which is required for tests running on ubuntu - run: sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev + run: | + sudo apt-get update + sudo apt-get -y install libgdiplus libgif-dev libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev - name: Git Config shell: bash diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs index 781b8246ff..21e1b55cfc 100644 --- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs +++ b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs @@ -217,7 +217,7 @@ private WebpImageInfo ReadVp8Info(BufferedReadStream stream, ImageMetadata metad else { // Ignore unknown chunks. - uint chunkSize = ReadChunkSize(stream, buffer); + uint chunkSize = ReadChunkSize(stream, buffer, false); stream.Skip((int)chunkSize); } } @@ -500,9 +500,10 @@ private static WebpChunkType ReadChunkType(BufferedReadStream stream, Span /// /// The stream to decode from. /// Temporary buffer. + /// If true, the chunk size is required to be read, otherwise it can be skipped. /// The chunk size in bytes. /// Invalid data. - private static uint ReadChunkSize(BufferedReadStream stream, Span buffer) + private static uint ReadChunkSize(BufferedReadStream stream, Span buffer, bool required = true) { if (stream.Read(buffer, 0, 4) == 4) { @@ -510,7 +511,13 @@ private static uint ReadChunkSize(BufferedReadStream stream, Span buffer) return (chunkSize % 2 == 0) ? chunkSize : chunkSize + 1; } - throw new ImageFormatException("Invalid Webp data."); + if (required) + { + throw new ImageFormatException("Invalid Webp data."); + } + + // Return the size of the remaining data in the stream. + return (uint)(stream.Length - stream.Position); } /// diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index 29362105db..d81cd20849 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs @@ -549,4 +549,14 @@ public void Identify_VerifyRatio(string imagePath) Assert.Equal(37.8, meta.VerticalResolution); Assert.Equal(PixelResolutionUnit.PixelsPerCentimeter, meta.ResolutionUnits); } + + [Theory] + [WithFile(Lossy.Issue2925, PixelTypes.Rgba32)] + public void WebpDecoder_CanDecode_Issue2925(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(WebpDecoder.Instance); + image.DebugSave(provider); + image.CompareToOriginal(provider, ReferenceDecoder); + } } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 0c73860e9c..5a7c2e66ea 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -859,6 +859,7 @@ public static class Lossy public const string Issue2763 = "Webp/issues/Issue2763.png"; public const string Issue2801 = "Webp/issues/Issue2801.webp"; public const string Issue2866 = "Webp/issues/Issue2866.webp"; + public const string Issue2925 = "Webp/issues/Issue2925.webp"; } } diff --git a/tests/Images/Input/Webp/issues/Issue2925.webp b/tests/Images/Input/Webp/issues/Issue2925.webp new file mode 100644 index 0000000000..414a06caad --- /dev/null +++ b/tests/Images/Input/Webp/issues/Issue2925.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e12207babf122af7a62246938c2e78faa0d3f730edb3182f4f9d6adae6bfc602 +size 262144