always check memory area length

vips_image_new_from_memory() allowed you to use length == 0 to mean
"don't check memory length". This was part of some very old vips7
compatibility.

The ppm loader could pass length == 0 if header size was equal to file
size, bypassing the length check.
This commit is contained in:
John Cupitt 2019-12-14 05:13:44 +00:00
parent e236f19f97
commit 1fd3b478e1
2 changed files with 5 additions and 7 deletions

View File

@ -65,8 +65,8 @@
*/
/*
#define DEBUG
*/
#define DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -426,6 +426,7 @@ vips_foreign_load_ppm_generate_binary( VipsRegion *or,
{
VipsRect *r = &or->valid;
VipsForeignLoadPpm *ppm = (VipsForeignLoadPpm *) a;
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( ppm );
VipsImage *image = or->im;
size_t sizeof_line = VIPS_IMAGE_SIZEOF_LINE( image );
@ -438,7 +439,8 @@ vips_foreign_load_ppm_generate_binary( VipsRegion *or,
bytes_read = vips_streami_read( ppm->streami, q, sizeof_line );
if( bytes_read != sizeof_line ) {
vips_error( "ppmload", "%s", _( "file truncated" ) );
vips_error( class->nickname,
"%s", _( "file truncated" ) );
return( -1 );
}
}

View File

@ -2072,11 +2072,7 @@ vips_image_new_from_memory( const void *data, size_t size,
return( NULL );
}
/* Allow len == 0, meaning don't check. Used for im_image()
* compatibility.
*/
if( size > 0 &&
size < VIPS_IMAGE_SIZEOF_IMAGE( image ) ) {
if( size < VIPS_IMAGE_SIZEOF_IMAGE( image ) ) {
vips_error( "VipsImage",
_( "memory area too small --- "
"should be %" G_GINT64_FORMAT " bytes, "