I am using .NET Core 3.0 MVC app with a file upload for users. These files assumed to be an image, but for obvious reasons, I validate the image before saving it to the server.
Now I have ran into an issue, when a user tries to upload a JPEG image (which seems to be fine as he had to email it to me for further inspection) and this image seems to be a WebP image or was converted from a WebP Image.
The issue is that one of the check for each image is
using (var bitmap = new Bitmap(postedFile.OpenReadStream()))
{
}
This threw an exception "Parameter is not valid" and because of this, validation fails.
If I read the buffer of the uploaded IFromFile
, it starts with RIFFڶ\0\0WEBPVP8
This is how I knew, this is not a normal image.
Any way to decode or validate this image as any other?