-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
image/jpeg: unexpected EOF when decoding image file #45902
Comments
Output from GraphicsMagick indicates this file is an invalid JPEG file ( Outputs from "gm identify"$ gm identify -verbose 1.jpg
Image: 1.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Geometry: 705x725
Class: DirectClass
Type: true color
Depth: 8 bits-per-pixel component
Channel Depths:
Red: 8 bits
Green: 8 bits
Blue: 8 bits
Channel Statistics:
Red:
Minimum: 0.00 (0.0000)
Maximum: 65535.00 (1.0000)
Mean: 58898.59 (0.8987)
Standard Deviation: 13043.94 (0.1990)
Green:
Minimum: 0.00 (0.0000)
Maximum: 65535.00 (1.0000)
Mean: 52892.09 (0.8071)
Standard Deviation: 21055.03 (0.3213)
Blue:
Minimum: 0.00 (0.0000)
Maximum: 65535.00 (1.0000)
Mean: 55775.47 (0.8511)
Standard Deviation: 17834.50 (0.2721)
Filesize: 201.3Ki
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD
Page geometry: 705x725+0+0
Compose: Over
Dispose: Undefined
Iterations: 0
Compression: JPEG
JPEG-Quality: 100
JPEG-Colorspace: 2
JPEG-Colorspace-Name: RGB
JPEG-Sampling-factors: 2x2,1x1,1x1
Signature: 4daca6d3d493e6799e0f0a383b8f5acb746e7e4287984fe7418877241978b57f
Profile-EXIF: 50 bytes
Orientation: 0
Exif Offset: 38
Tainted: False
User Time: 0.010u
Elapsed Time: 0m:0.009465s
Pixels Per Second: 51.5Mi
gm identify: Premature end of JPEG file (1.jpg). |
@ZekeLu I don't think this jpeg is "invalid", haven't heard of that tool and its output doesn't make any sense to me. I know that file was created by regular user with some very basic tools, such as Adobe Photoshop/scanning software. There are more examples. What I know for sure is that image is correctly opened by all possible software on my machine: Browsers:
Editors:
As I said Image Magic tools resize and crop this image without any error, producing valid results. |
Disagree. This fact clearly indicates that nothing prevents from decoding and processing an image, and Image Magic is de-facto industry standard for all sorts of image processing. It's an addition to a quite decent list of software which doesn't treat that image as "invalid". My criteria for validity (as well as of my users) if that major web browser can read and display an image. In real world you will see tons of such images. |
I meant being able to do operations (scale/rotate/crop/etc...) on the image is irreverent. The important thing is being able to load it. |
While waiting for this issue to be resolved, you could use another jpeg library e.g. |
Use the @ZekeLu also pointed out that your problem is already discussed in issue #10447. |
Sorry that I didn't make it clear that when I said the image is invalid, I meant from the perspective of the encoding standard. I just tried ImageMagick, and it reports the same result: Outputs from "magick identify"
|
Yeah, duplicate of #10447 |
@nigeltao This kind of error was never mentioned in #10447, and error I see absolutely meaningless. It's not
@ZekeLu As I said I'm using Image Magick bindings to crop/resize the image and it decodes, manipulates given file with no issues. That was the point. I don't care if any specific tool can detect that file is not perfect. You will never have a chance to work only with perfect images in the wild, and it just makes I read that issue and according to comments from @bradfitz, Go should follow what browsers do. Is this approach changed?
@AlexRouSg Thanks, we are using |
@inliquid, in fact, I'm with you 🤝 . I wish In my opinion, this issue can not be addressed without #10447 being addressed, and it doesn't help to just leave this one open. #10447 is tagged as |
All their functions are taking an argument of |
@AlexRouSg as I said, we want auto orientation feature, and it works with use of img, err := imaging.Open("test.jpg", imaging.AutoOrientation(true)) or with direct call of |
@inliquid Sorry I have a bad habbit of reply too fast, was trying to give you options on how to make it work but I see now that it's likely not worth the effort now that you are using image magic. |
There are two concerns here.
As for (1), that is a duplicate of #10447, as previously mentioned. Even if we 'fixed' (2), we can't solve your underlying problem (you want as much of the JPEG as you can still decode, even if it's overall technically an invalid JPEG) without solving (1). As for (2),
|
As I said, and as you can clearly see, because you are an active participant of that issue, there is no mention of
What's the point? You are talking about some internals of
You just said what it sounds: "premature end of [something you just processed] JPEG".
Ok, nice. I don't know if their use of And, again what's the point to referring to them? So if, lets imagine, their use of |
In volunteer projects, It may be more productive to contribute working code. |
As I said, there are two concerns. Concern (1) is that the Go standard library doesn't give you 'best effort' partial results when asked to decode an invalid image. To repeat what other commentators have said above, these images are invalid according to the JPEG specification. Concern (1) is a duplicate of #10447. To repeat, even if we returned a different error, you wouldn't see any difference in:
in your original code snippet.
Concern (2) is that it returns For better or worse, this is how the standard library has behaved (for I'll re-open this issue, specifically for people searching for |
This is just a stupid form. I wrote quite a lot in this thread since that, if you didn't notice. |
Try package main
import (
"image"
_ "image/jpeg"
"os"
)
func main() {
f, err := os.Open("1.jpg")
if err != nil {
panic(err)
}
defer f.Close()
f.Seek(0, 0)
_, _, err = image.Decode(f)
if err != nil {
panic(err)
}
} |
Found this here, although I'm really not sure how this should fix it: - golang/go#45902 (comment) According to the tests I added, the error "unexpected EOF" remains! At least this change shouldn't break anything either.... Help is more than welcome if someone has more time to read through all the issue comments.
I figured this because some image file from Samsung Galaxy Panorama Image, which does not have EOI marker from this adobe forum. https://community.adobe.com/t5/lightroom-classic-discussions/samsung-s9-panoramic-jpeg/td-p/10379560 And solved it by appending two bytes at the end of the buffer before passing it to .Decode
|
Hello 👋 I'm not familiar with go and I just came here as Photoprism seems to use go to open up images and I've got some from my galaxy s8 (when doing panoramas) that have this EOF issue. Any chance the fix above (or something else) will be integrated in the main branch / fixed? Or is it something that should be fixed not by go but rather on the consumer side? Thanks |
it works fine for me , thanks for saving my day |
aCropalypse (CVE 2023-21036): https://en.wikipedia.org/wiki/ACropalypse |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I work with a web platform, where multiple users can post their content, including images. We're moving from legacy solution based on PHP and re-implementing it in Go. One of the functionality required for a platform is resizing/cropping images. We used
github.com/disintegration/imaging
for that and encountered this problem with that library originally. What happens is that for some particularjpeg
images, there is an error when you try to decode it using standard library.Please note, that Firefox/Chrome/etc browsers open and display that image correctly, as well as
imagick
(part of legacy solution) does resize/cropping of it without any problems. Withimage/jpeg
I'm gettingunexpected EOF
when trying to decode an image.Here is a sample code to reproduce an error:
Output:
Archived image:
1.zip
What did you expect to see?
No panic.
What did you see instead?
Panic.
The text was updated successfully, but these errors were encountered: