Browse Source

Throw exception, if a transform is present more than once

pull/1552/head
Brian Popow 6 years ago
parent
commit
309f1f83c6
  1. 3
      src/ImageSharp/Formats/WebP/LosslessUtils.cs
  2. 7
      src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs

3
src/ImageSharp/Formats/WebP/LosslessUtils.cs

@ -164,9 +164,10 @@ namespace SixLabors.ImageSharp.Formats.WebP
} }
/// <summary> /// <summary>
/// This will reverse the predictor transform.
/// The predictor transform can be used to reduce entropy by exploiting the fact that neighboring pixels are often correlated. /// The predictor transform can be used to reduce entropy by exploiting the fact that neighboring pixels are often correlated.
/// In the predictor transform, the current pixel value is predicted from the pixels already decoded (in scan-line order) and only the residual value (actual - predicted) is encoded. /// In the predictor transform, the current pixel value is predicted from the pixels already decoded (in scan-line order) and only the residual value (actual - predicted) is encoded.
/// The prediction mode determines the type of prediction to use. We divide the image into squares and all the pixels in a square use same prediction mode. /// The prediction mode determines the type of prediction to use. The image is divided into squares and all the pixels in a square use same prediction mode.
/// </summary> /// </summary>
/// <param name="transform">The transform data.</param> /// <param name="transform">The transform data.</param>
/// <param name="pixelData">The pixel data to apply the inverse transform.</param> /// <param name="pixelData">The pixel data to apply the inverse transform.</param>

7
src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs

@ -617,6 +617,13 @@ namespace SixLabors.ImageSharp.Formats.WebP
{ {
var transformType = (Vp8LTransformType)this.bitReader.ReadBits(2); var transformType = (Vp8LTransformType)this.bitReader.ReadBits(2);
var transform = new Vp8LTransform(transformType, xSize, ySize); var transform = new Vp8LTransform(transformType, xSize, ySize);
// Each transform is allowed to be used only once.
if (decoder.Transforms.Any(t => t.TransformType == transform.TransformType))
{
WebPThrowHelper.ThrowImageFormatException("Each transform can only be present once");
}
switch (transformType) switch (transformType)
{ {
case Vp8LTransformType.SubtractGreen: case Vp8LTransformType.SubtractGreen:

Loading…
Cancel
Save