Browse Source

Merge pull request #1078 from SixLabors/js/fix-1076

Remove invalid Subsampling checks.
af/merge-core
James Jackson-South 6 years ago
committed by GitHub
parent
commit
90d6c6f84e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  3. 5
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs
  4. 1
      tests/ImageSharp.Tests/TestImages.cs
  5. 2
      tests/Images/External
  6. 3
      tests/Images/Input/Jpg/issues/issue-1076-invalid-subsampling.jpg

11
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs

@ -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;
@ -22,11 +22,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.Frame = frame;
this.Id = id;
// Valid sampling factors are 1..2
if (horizontalFactor == 0
|| verticalFactor == 0
|| horizontalFactor > 2
|| verticalFactor > 2)
// Validate sampling factors.
if (horizontalFactor == 0 || verticalFactor == 0)
{
JpegThrowHelper.ThrowBadSampling();
}
@ -138,4 +135,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.SpectralBlocks = this.memoryAllocator.Allocate2D<Block8x8>(width, height, AllocationOptions.Clean);
}
}
}
}

2
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -764,7 +764,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
for (int i = 0; i < this.ComponentCount; i++)
{
byte hv = this.temp[index + 1];
int h = hv >> 4;
int h = (hv >> 4) & 15;
int v = hv & 15;
if (maxH < h)

5
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs

@ -31,6 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Issues.InvalidAPP0721,
TestImages.Jpeg.Issues.ExifGetString750Load,
TestImages.Jpeg.Issues.ExifGetString750Transform,
TestImages.Jpeg.Issues.BadSubSampling1076,
// LibJpeg can open this despite the invalid density units.
TestImages.Jpeg.Issues.Fuzz.ArgumentOutOfRangeException825B,
@ -38,6 +39,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
// LibJpeg can open this despite incorrect colorspace metadata.
TestImages.Jpeg.Issues.IncorrectColorspace855,
// LibJpeg can open this despite the invalid subsampling units.
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824C,
// High depth images
TestImages.Jpeg.Baseline.Testorig12bit,
};
@ -71,7 +75,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestImages.Jpeg.Issues.Fuzz.NullReferenceException823,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824A,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824B,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824C,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824D,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824E,
TestImages.Jpeg.Issues.Fuzz.IndexOutOfRangeException824F,

1
tests/ImageSharp.Tests/TestImages.cs

@ -192,6 +192,7 @@ namespace SixLabors.ImageSharp.Tests
public const string IncorrectColorspace855 = "Jpg/issues/issue855-incorrect-colorspace.jpg";
public const string IncorrectResize1006 = "Jpg/issues/issue1006-incorrect-resize.jpg";
public const string ExifResize1049 = "Jpg/issues/issue1049-exif-resize.jpg";
public const string BadSubSampling1076 = "Jpg/issues/issue-1076-invalid-subsampling.jpg";
public static class Fuzz
{

2
tests/Images/External

@ -1 +1 @@
Subproject commit d8ea82085ac39a6aa6ca8e0806a9518d3a7d3337
Subproject commit b47190bd5cd450110f3849962512b918d2596ecf

3
tests/Images/Input/Jpg/issues/issue-1076-invalid-subsampling.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1507746a6c37697cb985fc7427709fd68478ff7cbdfe20f6cfbe7257ed6c7ccd
size 39149
Loading…
Cancel
Save