sindresorhus / file-type

Detect the file type of a file, stream, or data
MIT License
3.64k stars 345 forks source link

mimetype of certain PNGs mislabeled as "text/plan" #621

Closed jvnlwn closed 7 months ago

jvnlwn commented 7 months ago

In a recent release of filestack-js (v 3.29.0) https://github.com/filestack/filestack-js/commit/ec8a95001647bd1f5fc2d2a68f55da26b541e0b5, a bug was introduced when upgrading their file-type dependency.

When uploading certain PNGs via the filestack-js API, a PNG's mimetype might be mislabeled as "text/plan" rather than "image/png".

Here is a PNG which produced the error:

winding-path-banner

I cannot currently point to a change in file-type responsible, or provide a reproduction with file-type as I'm quite unfamiliar with this codebase.

The bug cannot be reproduced with filestack-js v 3.28.0, hence my suspicion leads me to file-type.

sindresorhus commented 7 months ago

I tried adding the image to our tests and it's correctly detected as PNG.

jvnlwn commented 7 months ago

@sindresorhus thank you for checking on that. It seems likely then that the bug lies with filestack-js. Will continue investigating with them, thanks!

jvnlwn commented 7 months ago

@sindresorhus there could still be an issue with file-type which maybe you can help determine.

Once again, looking at the changes in filestack-js, especially take note of these changes.

In my testing with filestack-js, using the file in this issue's description, I hit the exception caught from file-type's fromBuffer method.

In the console, I see the warning:

An exception occurred while processing the buffer: Buffer is not defined

The "Buffer is not defined" error could only be coming from file-type, no?

Borewit commented 7 months ago

file-type is primary written for Node.js and has a dependency on node:Buffer.. At this time it required you properly shim the Buffer requirement in a non Node.js environment.

jvnlwn commented 7 months ago

Thanks @Borewit, that makes sense. Guessing the behavior is expected in filestack-js – maybe they intend for the library to be used in either a Web or Node.js env.