Code

Fix crash when trying to import a corrupted PNG file.
authorKrzysztof Kosiński <tweenk.pl@gmail.com>
Sun, 31 Jan 2010 20:38:02 +0000 (21:38 +0100)
committerKrzysztof Kosiński <tweenk.pl@gmail.com>
Sun, 31 Jan 2010 20:38:02 +0000 (21:38 +0100)
src/sp-image.cpp

index daf5e9e88577c98ac51fd2677973a6fb6c78ed39..22b83670359662d3922bd37dd997d5f8adf6907a 100644 (file)
@@ -328,6 +328,16 @@ static GdkPixbuf* pixbuf_new_from_file( const char *filename, time_t &modTime, g
                                 );
                             if ( pngPtr )
                             {
+                                if ( setjmp(png_jmpbuf(pngPtr)) )
+                                {
+                                    // libpng calls longjmp to return here if an error occurs.
+                                    png_destroy_read_struct( &pngPtr, &infoPtr, NULL );
+                                    fclose(fp);
+                                    gdk_pixbuf_loader_close(loader, NULL);
+                                    g_object_unref(loader);
+                                    return NULL;
+                                }
+
                                 infoPtr = png_create_info_struct( pngPtr );
                                 //endPtr = png_create_info_struct( pngPtr );