diff options
Diffstat (limited to 'Emby.Drawing/Common/ImageHeader.cs')
| -rw-r--r-- | Emby.Drawing/Common/ImageHeader.cs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Emby.Drawing/Common/ImageHeader.cs b/Emby.Drawing/Common/ImageHeader.cs index 4f56498a5..121e20deb 100644 --- a/Emby.Drawing/Common/ImageHeader.cs +++ b/Emby.Drawing/Common/ImageHeader.cs @@ -27,10 +27,10 @@ namespace Emby.Drawing.Common /// The image format decoders /// </summary> private static readonly KeyValuePair<byte[], Func<BinaryReader, ImageSize>>[] ImageFormatDecoders = new Dictionary<byte[], Func<BinaryReader, ImageSize>> - { - { new byte[] { 0x42, 0x4D }, DecodeBitmap }, - { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif }, - { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif }, + { + { new byte[] { 0x42, 0x4D }, DecodeBitmap }, + { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif }, + { new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif }, { new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng }, { new byte[] { 0xff, 0xd8 }, DecodeJfif } @@ -38,6 +38,8 @@ namespace Emby.Drawing.Common private static readonly int MaxMagicBytesLength = ImageFormatDecoders.Select(i => i.Key.Length).OrderByDescending(i => i).First(); + private static string[] SupportedExtensions = new string[] { ".jpg", ".jpeg", ".png", ".gif" }; + /// <summary> /// Gets the dimensions of an image. /// </summary> @@ -48,6 +50,17 @@ namespace Emby.Drawing.Common /// <exception cref="ArgumentException">The image was of an unrecognised format.</exception> public static ImageSize GetDimensions(string path, ILogger logger, IFileSystem fileSystem) { + var extension = Path.GetExtension(path); + + if (string.IsNullOrEmpty(extension)) + { + throw new ArgumentException("ImageHeader doesn't support image file"); + } + if (!SupportedExtensions.Contains(extension)) + { + throw new ArgumentException("ImageHeader doesn't support " + extension); + } + using (var fs = fileSystem.OpenRead(path)) { using (var binaryReader = new BinaryReader(fs)) |
