diff options
author | Bastien Nocera <hadess@hadess.net> | 2017-12-05 06:39:45 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2017-12-05 06:42:12 +0100 |
commit | b99e04f116972d2ee355fb129238cc574bd58dd3 (patch) | |
tree | 27219ad627bf607a42888889c50e9e1b1d8e8567 /gdk-pixbuf | |
parent | fa472afe93ecf4a1863d4fcbe79cccad5a613faf (diff) | |
download | gdk-pixbuf-b99e04f116972d2ee355fb129238cc574bd58dd3.tar.gz |
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.
https://bugzilla.gnome.org/show_bug.cgi?id=753605
Diffstat (limited to 'gdk-pixbuf')
-rw-r--r-- | gdk-pixbuf/io-jpeg.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c index 1e7fcd039..1cd3d3019 100644 --- a/gdk-pixbuf/io-jpeg.c +++ b/gdk-pixbuf/io-jpeg.c @@ -100,7 +100,8 @@ static gboolean gdk_pixbuf__jpeg_image_stop_load (gpointer context, GError **err static gboolean gdk_pixbuf__jpeg_image_load_increment(gpointer context, const guchar *buf, guint size, GError **error); - +static gboolean gdk_pixbuf__jpeg_image_load_lines (JpegProgContext *context, + GError **error); static void fatal_error_handler (j_common_ptr cinfo) @@ -848,7 +849,23 @@ gdk_pixbuf__jpeg_image_stop_load (gpointer data, GError **error) g_return_val_if_fail (context != NULL, TRUE); cinfo = &context->cinfo; - + + /* Try to finish loading truncated files */ + if (cinfo->output_scanline < cinfo->output_height) { + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* But only if there's enough buffer space left */ + if (src->skip_next < sizeof(src->buffer) - 2) { + /* Insert a fake EOI marker */ + src->buffer[src->skip_next] = (JOCTET) 0xFF; + src->buffer[src->skip_next + 1] = (JOCTET) JPEG_EOI; + src->pub.next_input_byte = src->buffer + src->skip_next; + src->pub.bytes_in_buffer = 2; + + gdk_pixbuf__jpeg_image_load_lines (context, NULL); + } + } + /* FIXME this thing needs to report errors if * we have unused image data */ |