GNOME Bugzilla – Bug 753605
Inconsistent error handling with jpeg file (new_from_file vs new_from_file_at_size)
Last modified: 2017-12-06 08:33:26 UTC
Created attachment 309240 [details] image The attached image loads successfully when using gdk_pixbuf_new_from_file but fails when using gdk_pixbuf_new_from_file_at_size with the following error: gdk-pixbuf-error-quark: Error interpreting JPEG image file (Application transferred too few scanlines) (0) There seems to be something wrong with the file as imagemagick complains with "Premature end of JPEG file", but the difference in error handling seems weird.
Created attachment 364966 [details] [review] tests: Add test for bug 753605
This might be a case of libjpeg sucking, but I'm not certain. When going down the gdk_pixbuf_new_from_file_at_size() path, we just pass a FILE * to libjpeg, and it does the work of loading the data as it needs. When using gdk_pixbuf_new_from_file_at_size(), we open the FILE * ourselves, and read it byte-by-byte, and checking on libjpeg to see if it managed to load it. This is when it fails.
Misread the code, it's loading 64kB by 64kB.
Created attachment 364996 [details] [review] tests: Add test for bug 753605
Created attachment 364997 [details] [review] jpeg: Use a temporary variable To avoid using context->cinfo all the time.
Created attachment 364998 [details] [review] jpeg: Fix loading truncated incremental inputs When loading incremental inputs through a GdkPixbufLoader, we didn't have any code replicating the stdio_fill_input_buffer() hack to finish up a file. Adding those markers makes libjpeg think that the file was at least closed properly, and will attempt decoding.
The bad news is that the file is broken. The good news is that we can cover it up, and you won't notice it :) Attachment 364996 [details] pushed as 73855e7 - tests: Add test for bug 753605 Attachment 364997 [details] pushed as fa472af - jpeg: Use a temporary variable Attachment 364998 [details] pushed as b99e04f - jpeg: Fix loading truncated incremental inputs
Thank you!