revise fail handling, again

clarify policy on file read errors and warnings:

* if the file format library reports a warning, we log it in vips, but
that's all
* if the file format library reports an error, we log it, but try to
continue
* if the file format library reports an error and fail is set, we log it
and fail

all loaders now implement this
This commit is contained in:
John Cupitt 2017-05-12 17:22:49 +01:00
parent 2b75a372d1
commit 942b0446a3
6 changed files with 19 additions and 25 deletions

View File

@ -1,6 +1,7 @@
23/4/17 started 8.5.5
- doc polishing
- more improvements for truncated PNG files, thanks juyunsang
- improve corrupted jpg handling, thanks juyunsang
23/4/17 started 8.5.4
- don't depend on image width when setting n_lines, thanks kleisauke

View File

@ -193,7 +193,7 @@ vips_foreign_load_csv_init( VipsForeignLoadCsv *csv )
* * @lines: read this many lines from file
* * @whitespace: set of whitespace characters
* * @separator: set of separator characters
* * @fail: %gboolean, fail on warnings
* * @fail: %gboolean, fail on errors
*
* Load a CSV (comma-separated values) file. The output image is always 1
* band (monochrome), #VIPS_FORMAT_DOUBLE. Use vips_bandfold() to turn
@ -221,7 +221,7 @@ vips_foreign_load_csv_init( VipsForeignLoadCsv *csv )
* @separator sets the characters that separate fields.
* Default ;,<emphasis>tab</emphasis>. Separators are never run together.
*
* Setting @fail to %TRUE makes the reader fail on any warnings.
* Setting @fail to %TRUE makes the reader fail on any errors.
*
* See also: vips_image_new_from_file(), vips_bandfold().
*

View File

@ -1016,7 +1016,7 @@ vips_foreign_load_class_init( VipsForeignLoadClass *class )
VIPS_ARG_BOOL( class, "fail", 11,
_( "Fail" ),
_( "Fail on first warning" ),
_( "Fail on first error" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoad, fail ),
FALSE );

View File

@ -85,6 +85,8 @@
* - don't warn for missing exif res, since we fall back to jfif now
* 17/1/17
* - invalidate operation on read error
* 12/5/17
* - fail aborts on error, not warning
*/
/*
@ -148,7 +150,7 @@ typedef struct _ReadJpeg {
*/
int shrink;
/* Fail on warnings.
/* Fail on errors.
*/
gboolean fail;
@ -526,10 +528,10 @@ read_jpeg_generate( VipsRegion *or,
int y;
#ifdef DEBUG
#ifdef DEBUG_VERBOSE
printf( "read_jpeg_generate: %p line %d, %d rows\n",
g_thread_self(), r->top, r->height );
#endif /*DEBUG*/
#endif /*DEBUG_VERBOSE*/
VIPS_GATE_START( "read_jpeg_generate: work" );
@ -565,23 +567,14 @@ read_jpeg_generate( VipsRegion *or,
if( setjmp( jpeg->eman.jmp ) ) {
VIPS_GATE_STOP( "read_jpeg_generate: work" );
return( -1 );
}
#ifdef DEBUG
printf( "read_jpeg_generate: lonjmp() exit\n" );
#endif /*DEBUG*/
/* If --fail is set, we make read fail on any warnings. This will stop
* on any errors from the previous jpeg_read_scanlines().
*/
if( jpeg->eman.pub.num_warnings > 0 &&
jpeg->fail ) {
VIPS_GATE_STOP( "read_jpeg_generate: work" );
if( jpeg->fail )
return( -1 );
/* Only fail once.
*/
jpeg->eman.pub.num_warnings = 0;
*stop = TRUE;
return( -1 );
return( 0 );
}
for( y = 0; y < r->height; y++ ) {

View File

@ -328,7 +328,7 @@ vips_foreign_load_jpeg_buffer_init( VipsForeignLoadJpegBuffer *buffer )
* Optional arguments:
*
* * @shrink: %gint, shrink by this much on load
* * @fail: %gboolean, fail on warnings
* * @fail: %gboolean, fail on errors
* * @autorotate: %gboolean, use exif Orientation tag to rotate the image
* during load
*
@ -339,7 +339,7 @@ vips_foreign_load_jpeg_buffer_init( VipsForeignLoadJpegBuffer *buffer )
* are 1, 2, 4 and 8. Shrinking during read is very much faster than
* decompressing the whole image and then shrinking later.
*
* Setting @fail to %TRUE makes the JPEG reader fail on any warnings.
* Setting @fail to %TRUE makes the JPEG reader fail on any errors.
* This can be useful for detecting truncated files, for example. Normally
* reading these produces a warning, but no fatal error.
*
@ -406,7 +406,7 @@ vips_jpegload( const char *filename, VipsImage **out, ... )
* Optional arguments:
*
* * @shrink: %gint, shrink by this much on load
* * @fail: %gboolean, fail on warnings
* * @fail: %gboolean, fail on errors
* * @autorotate: %gboolean, use exif Orientation tag to rotate the image
* during load
*

View File

@ -38,9 +38,9 @@
*/
/*
*/
#define DEBUG_VERBOSE
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>