[gdk-pixbuf] jpeg: Fix loading truncated incremental inputs
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] jpeg: Fix loading truncated incremental inputs
- Date: Tue, 5 Dec 2017 05:44:01 +0000 (UTC)
commit b99e04f116972d2ee355fb129238cc574bd58dd3
Author: Bastien Nocera <hadess hadess net>
Date: Tue Dec 5 06:39:45 2017 +0100
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
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 1e7fcd0..1cd3d30 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
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]