From 0982d0efbbfe0f020491f12687812f6953d5592d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 28 Dec 2020 22:46:33 +0000 Subject: [PATCH 1/5] signal error on EOF in jpegload more reliably we were only warning on EOF in the read stub, even if fail was set thanks bozaro see https://github.com/libvips/libvips/issues/1946 --- ChangeLog | 1 + libvips/foreign/jpeg2vips.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 83ead3ac..a6a90323 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - don't seek on bad file descriptors [kleisauke] - check for null memory sources [kleisauke] - revise ppmload, fixing a couple of small bugs +- signal error on EOF in jpegload more reliably [bozaro] 18/12/20 started 8.10.5 - fix potential /0 in animated webp load [lovell] diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 08d8e7c3..6ac491df 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -212,6 +212,7 @@ typedef struct { /* Private stuff during read. */ + ReadJpeg *jpeg; VipsSource *source; unsigned char buf[SOURCE_BUFFER_SIZE]; @@ -248,7 +249,10 @@ source_fill_input_buffer( j_decompress_ptr cinfo ) src->pub.bytes_in_buffer = read; } else { - WARNMS( cinfo, JWRN_JPEG_EOF ); + if( src->jpeg->fail ) + ERREXIT( cinfo, JERR_INPUT_EOF ); + else + WARNMS( cinfo, JWRN_JPEG_EOF ); src->pub.next_input_byte = eoi_buffer; src->pub.bytes_in_buffer = 2; } @@ -294,6 +298,7 @@ readjpeg_open_input( ReadJpeg *jpeg ) sizeof( Source ) ); src = (Source *) cinfo->src; + src->jpeg = jpeg; src->source = jpeg->source; src->pub.init_source = source_init_source; src->pub.fill_input_buffer = source_fill_input_buffer; From 7cda6e59573d1efcb55d744906b6bc1dfdf9d0bf Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 29 Dec 2020 13:01:54 +0100 Subject: [PATCH 2/5] Switch VIPS_FCLIP to VIPS_CLIP in vips_scRGB2{BW,sRGB} --- libvips/colour/scRGB2BW.c | 2 +- libvips/colour/scRGB2sRGB.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libvips/colour/scRGB2BW.c b/libvips/colour/scRGB2BW.c index d378ca06..f838e74d 100644 --- a/libvips/colour/scRGB2BW.c +++ b/libvips/colour/scRGB2BW.c @@ -113,7 +113,7 @@ vips_scRGB2BW_line_16( unsigned short * restrict q, float * restrict p, q += 1; for( j = 0; j < extra_bands; j++ ) - q[j] = VIPS_FCLIP( 0, p[j] * 256.0, USHRT_MAX ); + q[j] = VIPS_CLIP( 0, (int) (p[j] * 256.0), USHRT_MAX ); p += extra_bands; q += extra_bands; } diff --git a/libvips/colour/scRGB2sRGB.c b/libvips/colour/scRGB2sRGB.c index 636e77a1..79cfacb6 100644 --- a/libvips/colour/scRGB2sRGB.c +++ b/libvips/colour/scRGB2sRGB.c @@ -140,7 +140,7 @@ vips_scRGB2sRGB_line_16( unsigned short * restrict q, float * restrict p, q += 3; for( j = 0; j < extra_bands; j++ ) - q[j] = VIPS_FCLIP( 0, p[j] * 256.0, USHRT_MAX ); + q[j] = VIPS_CLIP( 0, (int) (p[j] * 256.0), USHRT_MAX ); p += extra_bands; q += extra_bands; } From 9b9843f698a1b111a14dcc9a66d2e5c57ae3eacc Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 29 Dec 2020 13:33:24 +0100 Subject: [PATCH 3/5] Exclude libpng load when building with libspng Similar to ce63fc1, but allowing libpng to be configured with -DPNG_NO_READ (i.e reading functionally disabled). --- libvips/foreign/vipspng.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index cad03afb..df3342fb 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -161,6 +161,8 @@ user_warning_function( png_structp png_ptr, png_const_charp warning_msg ) g_warning( "%s", warning_msg ); } +#ifndef HAVE_SPNG + #define INPUT_BUFFER_SIZE (4096) /* What we track during a PNG read. @@ -763,6 +765,8 @@ vips__png_isinterlaced_source( VipsSource *source ) return( interlace_type != PNG_INTERLACE_NONE ); } +#endif /*!defined(HAVE_SPNG)*/ + const char *vips__png_suffs[] = { ".png", NULL }; /* What we track during a PNG write. From 7e9c7059be46e7594dfec0616b2f8a940729d82b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 29 Dec 2020 13:40:36 +0100 Subject: [PATCH 4/5] Remove redundant -lstdc++ configure check This became unused after commit 346a9e7. --- configure.ac | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/configure.ac b/configure.ac index 62971591..2cbd2f53 100644 --- a/configure.ac +++ b/configure.ac @@ -141,24 +141,6 @@ AM_CONDITIONAL(ENABLE_DEPRECATED, [test x"$enable_deprecated" = x"yes"]) # this gets pasted into version.h as a #define AC_SUBST(VIPS_ENABLE_DEPRECATED) -# we are a C library with some optional C++ components inside it - -# on most platforms, but not all, we just include -lstdc++ in the link line -# for programs - -# we ought to have a proper configure test for this :( - -AC_MSG_CHECKING([for needs -lstdc++]) -case "$host_os" in - freebsd*) - vips_needs_stdcpp=no - ;; - *) - vips_needs_stdcpp=yes - ;; -esac -AC_MSG_RESULT([$vips_needs_stdcpp]) - AC_MSG_CHECKING([for native Win32]) case "$host" in *-*-mingw*) From 7a1fb2a62792ff97471f507cb5a9449f62d3475d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 29 Dec 2020 13:29:27 +0000 Subject: [PATCH 5/5] slight formatting improvement --- libvips/foreign/jpeg2vips.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 6ac491df..a646f365 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -253,6 +253,7 @@ source_fill_input_buffer( j_decompress_ptr cinfo ) ERREXIT( cinfo, JERR_INPUT_EOF ); else WARNMS( cinfo, JWRN_JPEG_EOF ); + src->pub.next_input_byte = eoi_buffer; src->pub.bytes_in_buffer = 2; }