Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3: Gracefully handle LZW overflows #2880

Merged
merged 5 commits into from
Feb 10, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ jobs:
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit

- name: Export Failed Output
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
325 changes: 193 additions & 132 deletions src/ImageSharp/Formats/Gif/LzwDecoder.cs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
Original file line number Diff line number Diff line change
@@ -334,4 +334,16 @@ public void IssueTooLargeLzwBits<TPixel>(TestImageProvider<TPixel> provider)
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}

// https://github.com/SixLabors/ImageSharp/issues/2859
[Theory]
[WithFile(TestImages.Gif.Issues.Issue2859_A, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.Issues.Issue2859_B, PixelTypes.Rgba32)]
public void Issue2859_LZWPixelStackOverflow<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage();
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
}
2 changes: 2 additions & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
@@ -535,6 +535,8 @@ public static class Issues
public const string Issue2450_B = "Gif/issues/issue_2450_2.gif";
public const string Issue2198 = "Gif/issues/issue_2198.gif";
public const string Issue2758 = "Gif/issues/issue_2758.gif";
public const string Issue2859_A = "Gif/issues/issue_2859_A.gif";
public const string Issue2859_B = "Gif/issues/issue_2859_B.gif";
}

public static readonly string[] Animated =
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Images/Input/Gif/issues/issue_2859_A.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Images/Input/Gif/issues/issue_2859_B.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Unchanged files with check annotations Beta

public abstract class SIMDBenchmarkBase<T>
where T : struct
{
protected T[] input;

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 13 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected T[] result;

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 15 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected T testValue;

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected Vector<T> testVector;

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected virtual T GetTestValue() => default;
public abstract class ToVector4<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
protected IMemoryOwner<TPixel> source;

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 17 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected IMemoryOwner<Vector4> destination;

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Bulk/ToVector4.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected Configuration Configuration => Configuration.Default;
public abstract class Resize<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private byte[] bytes = null;

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 19 in tests/ImageSharp.Benchmarks/Processing/Resize.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Member 'bytes' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)
private Image<TPixel> sourceImage;
public abstract class FromVector4<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
protected IMemoryOwner<Vector4> source;

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 21 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected IMemoryOwner<TPixel> destination;

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, macos-13, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, ubuntu-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, macos-13, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 23 in tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

GitHub Actions / Build (false, windows-latest, net7.0, 7.0.x, true, -x64, false)

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
protected Configuration Configuration => Configuration.Default;