glib.GError: Error interpreting JPEG image file (Unsupported marker type 0x05)
Asked Answered
J

1

9

I am using gtk.gdk.PixbufLoader since several years.

Today, I try to load a jpg file from a new android device and get this exception:

Traceback (most recent call last):
  File "myscript.py", line 118, in next
    loader.write(buf)
glib.GError: Error interpreting JPEG image file (Unsupported marker type 0x05)

The same file can be loaded in eog (eye of gnome) and I can use convert (from image-magick) with out error.

It happens for all files, not just one, this leads me to the conclusion that the files are not broken.

What could be wrong?

Here is one of the files: http://thomas-guettler.de/20160627_163057-0.jpg

Here is a snippet to reproduce the exception:

from gtk.gdk import PixbufLoader
pixbufloader=PixbufLoader()
chunksize=130000
fd=open('20160627_163057-0.jpg', 'rb')
while True:
    bytes=fd.read(chunksize)
    if not bytes:
        break
    print pixbufloader.write(bytes)
pixbufloader.close()

If you set chunksize to 1, then it works.

If I use 130000 as chunksize, then the first call to write() fails.

Jeanett answered 18/9, 2016 at 19:54 Comment(4)
It would probably be a good idea to include the code which triggers this so people can reproduce it…Mutant
@Mutant yes, you right. I added a small snippet to reproduce the exception.Jeanett
Why are you chunking the load? pixbufloader.write() expects a full image. I suppose you check for the returned boolean by the pixbufloader -> in the previous iteration before the exception you'd get 'false', as there is not enough data to decode an image. Then, you start in the middle of nowhere (and decoder is, as it seems, stateless), with an unknown marker.Kink
@Kink I chunk because I don't want my application to freeze during loading. I load in background (pre load) the next images. This code worked since about 6 years without modification. It broke after upgrade to Ubuntu 16.04.Jeanett
B
5

I worked on your code and got to the conclusion that exactly after chunksize = 69632,i.e. at chunksize = 69633,This error is shown. One more thing I noticed is that this error is file related.If I use any file other than this "20160627_163057-0.jpg" image,error does not occur.

So my conclusion is that this particular file has some problem. Please check, Thanks.

Buoyancy answered 28/9, 2016 at 12:29 Comment(7)
The file can be shown in eye-of-gnome and other image processors (jpgtopnm, convert (from image magick)). AND: loading does not fail if I load the file byte-by-byte with chunksize=1.Jeanett
I think the image is ok.Jeanett
OK, chunk sizes greater then 69633 seem to produce this error. Thank you for investigating this. A work around would be to use smaller chunk sizes.... but still a work around - not a solution.Jeanett
Yeah,Seems like it.Buoyancy
@guettli, I tried some more things with your code and Now I am pretty much sure that its a file related problem. Please check these links "serverfault.com/questions/248596/…" and "askubuntu.com/questions/24350/i-cant-open-jpg-files-what-to-do"Buoyancy
The Image seems ok in viewing but its encoding might have some issues.Buoyancy
A file is a sequence of bytes. It should not matter if you put in one byte after the other or all bytes at once. If the images is broken: Why does it work with a small chunk size?Jeanett

© 2022 - 2024 — McMap. All rights reserved.