Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first 3 bytes determine whether the file is a .jpeg file #429

Open
senk8 opened this issue Jan 20, 2023 · 3 comments
Open

The first 3 bytes determine whether the file is a .jpeg file #429

senk8 opened this issue Jan 20, 2023 · 3 comments
Assignees

Comments

@senk8
Copy link

senk8 commented Jan 20, 2023

Is your feature request related to a problem? Please describe.
Hello! When I was using the serverless-image-handler, I could not view files with a specific magic number (i.e. FFD8FFED).
This line seems to be the cause.
https://github.com/aws-solutions/serverless-image-handler/blob/develop/source/image-handler/image-request.ts#L441

To Reproduce
Place a file with magic number FFD8FFED in your S3 bucket and specify application/octet-stream for Content-Type.

The following error occurs.

{"status":500,"code":"RequestTypeError","message":"The file does not have an extension and the file type could not be inferred. Please ensure that your original image is of a supported file type (jpg, png, tiff, webp, svg). Refer to the documentation for additional guidance on forming image requests."}

Describe the feature you'd like

Can I make it so that only jpeg files use the first 3 bytes (FFD8FF) to determine the extension? Although there are almost no JPEG files with magic numbers that do not match a switch statement such as FFD8FFED, the first 3 bytes seem to be appropriate for determining 'image/jpeg'.

Best regards.

@dougtoppin
Copy link
Member

@senk8 thanks for your report. we will take a look at it and add it to our backlog

@ChiSamurai
Copy link

ChiSamurai commented Apr 15, 2024

I would vote to open this ticket again. In our case we had a valid (see [https://www.w3.org/Graphics/JPEG/itu-t81.pdf](the W3 JPEG specs) (Page 32) JPEG with a comment marker.
image. Imho the check for the JPEG magic number does only cover a small subset of all valid JSON file headers.

In combination with a S3 "content-type" metadata set to "binary/octet-stream" the service is not able to identify some valid JPEGs and to handle them.

@simonkrol
Copy link
Member

@ChiSamurai

I think that's fair, I'll open this back up and discuss with the team if adding it makes sense.

Thanks,
Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants