Browse Source

Fix

pull/1924/head
Dmitry Pentin 5 years ago
parent
commit
c682504b38
  1. 10
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  2. 3
      src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs

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

@ -472,7 +472,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
: JpegColorSpace.Cmyk;
}
JpegThrowHelper.ThrowInvalidImageContentException($"Unsupported color mode. Supported component counts 1, 3, and 4; found {componentCount}");
JpegThrowHelper.ThrowNotSupportedComponentCount(componentCount);
return default;
}
@ -998,6 +998,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// 1 byte: Number of components
byte componentCount = this.temp[5];
// Validate: componentCount more than 4 can lead to a buffer overflow during stream
// reading so we must limit it to 4
// We do not support jpeg images with more than 4 components anyway
if (componentCount > 4)
{
JpegThrowHelper.ThrowNotSupportedComponentCount(componentCount);
}
this.Frame = new JpegFrame(frameMarker, precision, frameWidth, frameHeight, componentCount);
remaining -= length;

3
src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs

@ -45,5 +45,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($"Image is too large to encode at {width}x{height} for JPEG format.");
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNotSupportedComponentCount(int componentCount) => throw new NotSupportedException($"Images with {componentCount} components are not supported.");
}
}

Loading…
Cancel
Save