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

Handle incorrect colorspace metadata. #885

Merged
merged 1 commit into from
Apr 15, 2019
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
13 changes: 6 additions & 7 deletions src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,14 @@ private JpegColorSpace DeduceJpegColorSpace()

if (this.ComponentCount == 3)
{
if (this.adobe.Equals(default) || this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYCbCr)
{
return JpegColorSpace.YCbCr;
}

if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown)
if (!this.adobe.Equals(default) && this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown)
{
return JpegColorSpace.RGB;
}

// Some images are poorly encoded and contain incorrect colorspace transform metadata.
// We ignore that and always fall back to the default colorspace.
return JpegColorSpace.YCbCr;
}

if (this.ComponentCount == 4)
Expand All @@ -419,7 +418,7 @@ private JpegColorSpace DeduceJpegColorSpace()
: JpegColorSpace.Cmyk;
}

JpegThrowHelper.ThrowImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");
JpegThrowHelper.ThrowImageFormatException($"Unsupported color mode. Supported component counts 1, 3, and 4; found {this.ComponentCount}");
return default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public partial class JpegDecoderTests
TestImages.Jpeg.Issues.ExifGetString750Load,
TestImages.Jpeg.Issues.ExifGetString750Transform,

// LibJpeg can open this despite the invalid desity units.
// LibJpeg can open this despite the invalid density units.
TestImages.Jpeg.Issues.Fuzz.ArgumentOutOfRangeException825B,

// LibJpeg can open this despite incorrect colorspace metadata.
TestImages.Jpeg.Issues.IncorrectColorspace855,

// High depth images
TestImages.Jpeg.Baseline.Testorig12bit,
};
Expand Down
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public static class Issues
public const string ExifGetString750Transform = "Jpg/issues/issue750-exif-tranform.jpg";
public const string ExifGetString750Load = "Jpg/issues/issue750-exif-load.jpg";
public const string IncorrectQuality845 = "Jpg/issues/Issue845-Incorrect-Quality99.jpg";
public const string IncorrectColorspace855 = "Jpg/issues/issue855-incorrect-colorspace.jpg";

public static class Fuzz
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Images/External
Submodule External updated 43 files
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_BikeGrayscale_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_BikeGrayscale_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_BikeGrayscale_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bike_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bike_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bike_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_BikeGrayscale_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_BikeGrayscale_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_BikeGrayscale_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_Bike_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_Bike_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_Bike_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_CalliphoraPartial_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_CalliphoraPartial_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_CalliphoraPartial_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_cross_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_cross_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Bounded_cross_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_CalliphoraPartial_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_CalliphoraPartial_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_CalliphoraPartial_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Solid50x50_(255,0,0,255)_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Solid50x50_(255,0,0,255)_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_Solid50x50_(255,0,0,255)_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern200x100_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern200x100_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern200x100_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern23x31_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern23x31_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern23x31_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern30x20_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern30x20_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_TestPattern30x20_R8_C1_G1.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_WorksWithAllPixelTypes_Bgr24.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_WorksWithAllPixelTypes_Bgra32.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_WorksWithAllPixelTypes_Gray8.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_cross_R16_C1_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_cross_R16_C2_G3.png
+ ReferenceOutput/BokehBlurTest/BokehBlurFilterProcessor_cross_R8_C1_G1.png
+ ReferenceOutput/JpegDecoderTests/DecodeBaselineJpeg_issue855-incorrect-colorspace.png
+ ReferenceOutput/ResizeTests/Resize_BasicSmall_BasicTestPattern15x12_(2÷3,1÷2).png
+ ReferenceOutput/ResizeTests/Resize_BasicSmall_BasicTestPattern2x256_(1÷1,1÷8).png
+ ReferenceOutput/ResizeTests/Resize_BasicSmall_BasicTestPattern2x32_(1÷1,1÷2).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.