From b166924b0ccf6d5c3b5b36d04b1d8f7df2072ef6 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 9 Jun 2000 19:41:29 +0000 Subject: [PATCH] setjmp for the png error handler. It seems setting the error handling 2000-06-09 Larry Ewing * gdk-pixbuf/io-png.c (gdk_pixbuf__png_image_load_increment): setjmp for the png error handler. It seems setting the error handling functions does not avoid the jump, and so not calling setjmp was causing the incremental loader to jump into lala land. (gdk_pixbuf__png_image_begin_load): setjmp for error handling, I'm not sure this one is actually required but the docs say it must be set for every call to a png_* function. Also changed the comment to reflect the fact that setting the error handlers does _not_ avoid the longjmp. --- gdk-pixbuf/ChangeLog | 12 ++++++++++++ gdk-pixbuf/io-png.c | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index 94e7ab728d..ec1014025c 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,15 @@ +2000-06-09 Larry Ewing + + * gdk-pixbuf/io-png.c (gdk_pixbuf__png_image_load_increment): + setjmp for the png error handler. It seems setting the error + handling functions does not avoid the jump, and so not calling + setjmp was causing the incremental loader to jump into lala land. + (gdk_pixbuf__png_image_begin_load): setjmp for error handling, I'm + not sure this one is actually required but the docs say it must be + set for every call to a png_* function. + Also changed the comment to reflect the fact that setting the + error handlers does _not_ avoid the longjmp. + 2000-06-06 Larry Ewing * gdk-pixbuf/gdk-pixbuf-loader.c (gdk_pixbuf_loader_frame_done): diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c index 4514194842..afd9ffdca2 100644 --- a/gdk-pixbuf/io-png.c +++ b/gdk-pixbuf/io-png.c @@ -220,7 +220,8 @@ gdk_pixbuf__png_image_load (FILE *f) free_buffer, NULL); } -/* These avoid the setjmp()/longjmp() crap in libpng */ +/* I wish these avoided the setjmp()/longjmp() crap in libpng instead + just allow you to change the error reporting. */ static void png_error_callback (png_structp png_read_ptr, png_const_charp error_msg); @@ -299,6 +300,7 @@ gdk_pixbuf__png_image_begin_load (ModulePreparedNotifyFunc prepare_func, /* Create the main PNG context struct */ + lc->png_read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, lc, /* error/warning callback data */ png_error_callback, @@ -309,6 +311,13 @@ gdk_pixbuf__png_image_begin_load (ModulePreparedNotifyFunc prepare_func, return NULL; } + if (setjmp (lc->png_read_ptr->jmpbuf)) { + if (lc->png_info_ptr) + png_destroy_read_struct(&lc->png_read_ptr, NULL, NULL); + g_free(lc); + return NULL; + } + /* Create the auxiliary context struct */ lc->png_info_ptr = png_create_info_struct(lc->png_read_ptr); @@ -357,7 +366,11 @@ gdk_pixbuf__png_image_load_increment(gpointer context, guchar *buf, guint size) lc->max_row_seen_in_chunk = -1; /* Invokes our callbacks as needed */ - png_process_data(lc->png_read_ptr, lc->png_info_ptr, buf, size); + if (setjmp (lc->png_read_ptr->jmpbuf)) { + return FALSE; + } else { + png_process_data(lc->png_read_ptr, lc->png_info_ptr, buf, size); + } if (lc->fatal_error_occurred) return FALSE; @@ -522,3 +535,7 @@ png_warning_callback(png_structp png_read_ptr, fprintf(stderr, "Warning loading PNG: %s\n", warning_msg); } + + + +