aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing/Common/ImageHeader.cs
diff options
context:
space:
mode:
authorstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
committerstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
commit48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch)
tree8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Drawing/Common/ImageHeader.cs
parentc32d8656382a0eacb301692e0084377fc433ae9b (diff)
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Drawing/Common/ImageHeader.cs')
-rw-r--r--Emby.Drawing/Common/ImageHeader.cs21
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))