Skip to content

fileHash fails in an unsafe way if the extension is wrong #3

@Zer0-

Description

@Zer0-

Consider any webp image that was renamed to have the jpg file extension. This happened to my server when someone uploaded such an image.

If I run run the fileHash function on this file I get a Left value. If I try to print this error value it starts to print, but then the program freezes:

Invalid marker used
Invalid Bitmap magic identifier
Invalid Gif signature : RIFFd

After this my code doesn't continue. There is something wrong with evaluating the error value that fileHash gives back. For now I am just ignoring the error message as a work-around.

So there are really two issues here:

  • the error value is unsafe to evaluate
  • I think fileHash can do a better job of determining the file type by looking at something other than the file extension. This way it can still compute a phash even if the extension is wrong. (if I rename the file everything works).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions