Skip to content
Permalink
Browse files

reorganise vipspng a little

so we only set max malloc in one place

see #1424
  • Loading branch information...
jcupitt committed Sep 11, 2019
1 parent 6489833 commit d290c971ab3b6851b46ddaa092abd5273e4da645
Showing with 21 additions and 23 deletions.
  1. +21 −23 libvips/foreign/vipspng.c
@@ -72,7 +72,7 @@
* 25/8/18
* - support xmp read/write
* 20/4/19
* - allow huge metadata
* - allow huge xmp metadata
*/

/*
@@ -267,6 +267,18 @@ read_new( VipsImage *out, gboolean fail )
return( read );
}

static void
read_info( Read *read )
{
/* By default, libpng refuses to open files with a metadata chunk
* larger than 8mb. We've seen real files with 20mb, so set 50mb.
*/
#ifdef HAVE_PNG_SET_CHUNK_MALLOC_MAX
png_set_chunk_malloc_max( read->pPng, 50 * 1024 * 1024 );
#endif /*HAVE_PNG_SET_CHUNK_MALLOC_MAX*/
png_read_info( read->pPng, read->pInfo );
}

static Read *
read_new_filename( VipsImage *out, const char *name, gboolean fail )
{
@@ -282,20 +294,13 @@ read_new_filename( VipsImage *out, const char *name, gboolean fail )

/* Catch PNG errors from png_read_info().
*/
if( setjmp( png_jmpbuf( read->pPng ) ) )
if( setjmp( png_jmpbuf( read->pPng ) ) ) {
read_destroy( read );
return( NULL );
}

/* Read enough of the file that png_get_interlace_type() will start
* working.
*
* By default, libpng refuses to open files with a metadata chunk
* larger than 8mb. We've seen real files with 20mb, so set 50mb.
*/
png_init_io( read->pPng, read->fp );
#ifdef HAVE_PNG_SET_CHUNK_MALLOC_MAX
png_set_chunk_malloc_max( read->pPng, 50 * 1024 * 1024 );
#endif /*HAVE_PNG_SET_CHUNK_MALLOC_MAX*/
png_read_info( read->pPng, read->pInfo );
read_info( read );

return( read );
}
@@ -807,19 +812,12 @@ read_new_buffer( VipsImage *out, const void *buffer, size_t length,

/* Catch PNG errors from png_read_info().
*/
if( setjmp( png_jmpbuf( read->pPng ) ) )
if( setjmp( png_jmpbuf( read->pPng ) ) ) {
read_destroy( read );
return( NULL );
}

/* Read enough of the file that png_get_interlace_type() will start
* working.
*
* By default, libpng refuses to open files with a metadata chunk
* larger than 8mb. We've seen real files with 20mb, so set 50mb.
*/
#ifdef HAVE_PNG_SET_CHUNK_MALLOC_MAX
png_set_chunk_malloc_max( read->pPng, 50 * 1024 * 1024 );
#endif /*HAVE_PNG_SET_CHUNK_MALLOC_MAX*/
png_read_info( read->pPng, read->pInfo );
read_info( read );

return( read );
}

0 comments on commit d290c97

Please sign in to comment.
You can’t perform that action at this time.