From eb8b6f25862da4f405f9f0081d07e0ac2cd6f595 Mon Sep 17 00:00:00 2001 From: Ildar Khayrutdinov Date: Sat, 2 Oct 2021 11:22:57 +0300 Subject: [PATCH] build fixes --- .../Formats/Tiff/TiffDecoderCore.cs | 32 ++++++++++++++++--- .../Formats/Tiff/TiffThrowHelper.cs | 2 +- .../Profiles/Exif/Values/ExifLong8Array.cs | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 6692b79919..9f0a4b5148 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -335,8 +335,20 @@ namespace SixLabors.ImageSharp.Formats.Tiff int stripIndex = i; for (int planeIndex = 0; planeIndex < stripsPerPixel; planeIndex++) { - ulong offset = stripOffsets.GetValue(stripIndex) switch { ulong val => val, Number val => (uint)val }; - ulong count = stripByteCounts.GetValue(stripIndex) switch { ulong val => val, Number val => (uint)val }; + ulong offset = stripOffsets.GetValue(stripIndex) switch + { + ulong val => val, + Number val => (uint)val, + _ => throw TiffThrowHelper.ThrowImageFormatException("Expected Number or Long8 array") + }; + + ulong count = stripByteCounts.GetValue(stripIndex) switch + { + ulong val => val, + Number val => (uint)val, + _ => throw TiffThrowHelper.ThrowImageFormatException("Expected Number or Long8 array") + }; + decompressor.Decompress( this.inputStream, offset, @@ -423,8 +435,20 @@ namespace SixLabors.ImageSharp.Formats.Tiff break; } - ulong offset = stripOffsets.GetValue(stripIndex) switch { ulong val => val, Number val => (uint)val }; - ulong count = stripByteCounts.GetValue(stripIndex) switch { ulong val => val, Number val => (uint)val }; + ulong offset = stripOffsets.GetValue(stripIndex) switch + { + ulong val => val, + Number val => (uint)val, + _ => throw TiffThrowHelper.ThrowImageFormatException("Expected Number or Long8 array") + }; + + ulong count = stripByteCounts.GetValue(stripIndex) switch + { + ulong val => val, + Number val => (uint)val, + _ => throw TiffThrowHelper.ThrowImageFormatException("Expected Number or Long8 array") + }; + decompressor.Decompress( this.inputStream, offset, diff --git a/src/ImageSharp/Formats/Tiff/TiffThrowHelper.cs b/src/ImageSharp/Formats/Tiff/TiffThrowHelper.cs index 3c541a786d..8223c445ae 100644 --- a/src/ImageSharp/Formats/Tiff/TiffThrowHelper.cs +++ b/src/ImageSharp/Formats/Tiff/TiffThrowHelper.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff /// /// The error message for the exception. [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage); + public static Exception ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage); [MethodImpl(InliningOptions.ColdPath)] public static Exception NotSupportedDecompressor(string compressionType) => throw new NotSupportedException($"Not supported decoder compression method: {compressionType}"); diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs index 618135e926..d75e685656 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif return ExifDataType.Long; } - foreach (ulong value in this.Value) + foreach (ulong value in this.Value) { if (value > uint.MaxValue) {