diff --git a/PluralKit.Bot/Errors.cs b/PluralKit.Bot/Errors.cs index 66f44bf9..403b01d6 100644 --- a/PluralKit.Bot/Errors.cs +++ b/PluralKit.Bot/Errors.cs @@ -34,6 +34,7 @@ namespace PluralKit.Bot { public static PKError AvatarFileSizeLimit(long size) => new PKError($"File size too large ({size.Bytes().ToString("#.#")} > {Limits.AvatarFileSizeLimit.Bytes().ToString("#.#")}), try shrinking or compressing the image."); public static PKError AvatarNotAnImage(string mimeType) => new PKError($"The given link does not point to an image{(mimeType != null ? $" ({mimeType.SanitizeMentions()})" : "")}. Make sure you're using a direct link (ending in .jpg, .png, .gif)."); public static PKError AvatarDimensionsTooLarge(int width, int height) => new PKError($"Image too large ({width}x{height} > {Limits.AvatarDimensionLimit}x{Limits.AvatarDimensionLimit}), try resizing the image."); + public static PKError AvatarInvalid => new PKError($"Could not read image file - perhaps it's corrupted or the wrong format. Try a different image."); public static PKError UserHasNoAvatar => new PKError("The given user has no avatar set."); public static PKError InvalidUrl(string url) => new PKError($"The given URL is invalid."); diff --git a/PluralKit.Bot/Utils.cs b/PluralKit.Bot/Utils.cs index d0d33a68..64659ff5 100644 --- a/PluralKit.Bot/Utils.cs +++ b/PluralKit.Bot/Utils.cs @@ -62,6 +62,7 @@ namespace PluralKit.Bot // Parse the image header in a worker var stream = await response.Content.ReadAsStreamAsync(); var image = await Task.Run(() => Image.Identify(stream)); + if (image == null) throw Errors.AvatarInvalid; if (image.Width > Limits.AvatarDimensionLimit || image.Height > Limits.AvatarDimensionLimit) // Check image size throw Errors.AvatarDimensionsTooLarge(image.Width, image.Height); }