onurzorluer / react-image-file-resizer

Resize Local Images with React 🌄 🌅
MIT License
313 stars 41 forks source link

Indeterminate result #66

Open thany opened 2 years ago

thany commented 2 years ago

Describe the bug When passing a file that isn't an image, AND doesn't have a type, the function never produces a usable result. The responseUriFunc is never called, and an error is never thrown.

To Reproduce Steps to reproduce the behavior:

  1. Either:
    1. Select a file that your OS or your browser doesn't recognize. For me it's a 7z file, for you it might be something else.
    2. Pass it a bogus file: new File([ /* presumably any data will do */ ], 'foo', { type: '' })
  2. Observe the responseUriFunc and any thrown errors by wrapping the Resizer.imageFileResizer in a try-catch.

Expected behavior Either of these options:

I noticed in the source code that if the filetype is empty, you just carry on trying to resize the image, which isn't an image. Filetype could never be empty in practice. Any file that is resizable, must also be recognized by the browser, and therefor must also have a valid filetype. Letting empty filetypes through seems like a bad idea.

Desktop (please complete the following information):

iuliathira commented 2 years ago

Hi! Did you find a solution to this? I'm facing the same problem trying to write some test using mock data

thany commented 2 years ago

No, but I imagine forking this project might not be a bad idea, seeing how development on this project is not exactly super active. It doesn't seem like it should be awfully difficult to fix.

(not meant to belittle the author - I'm sure he/she has other priorities)

thany commented 2 years ago

I also found that certain PNGs also produce an indeterminate result. I tried these:

This is just what I happen to have at hand. More testing is neccesary to get to a safe conclusion, but it seems like large PNG might be the possible culprit. I currently have no way to be sure how large is too large, if that's the problem.

I'm pretty sure this is new. I've seen the above two failing PNGs work, but somehow it's now broken.