allow open of truncated images, but block data access

This commit is contained in:
John Cupitt 2009-03-19 23:29:12 +00:00
parent 568065880a
commit 588aa082d3
6 changed files with 33 additions and 5 deletions

View File

@ -4,7 +4,8 @@
- configure spots support for "restrict"
- reset dcm:display-range on magick read to help DICOM
- saner im_buildlut() behaviour
- added im_gauss_imask_sep()
- added im_gauss_imask_sep()
- allow open of truncated images, but block pixel access
3/3/09 started 7.17.2
- im_magick2vips.c: allow funky bit depths, like 14 (thanks Mikkel)

5
TODO
View File

@ -49,6 +49,11 @@
WONTFIX for 7.18
================
- bilateral filtering, see:
http://en.wikipedia.org/wiki/Bilateral_filter
http://www.shellandslate.com/fastmedian.html
- try making vips_add(), an operator as a class
- need to write interpolate docs ... manpages and tutorial

View File

@ -359,6 +359,11 @@ typedef struct im__IMAGE {
GSList *evalstartfns; /* list of start eval callbacks */
GSList *preclosefns; /* list of pre-close callbacks */
GSList *invalidatefns; /* list of invalidate callbacks */
/* Set this to indicate a truncated file. We've been able to read the
* header, but don't try mapping any of it or you'll crash.
*/
int nodata;
} IMAGE;
/* Only define if IM_ENABLE_DEPRECATED is set.

View File

@ -31,6 +31,8 @@
* - added preclose and evalstart
* 9/8/08
* - lock global image list (thanks lee)
* 19/3/09
* - add nodata
*/
/*
@ -168,6 +170,8 @@ im_init( const char *filename )
im->preclosefns = NULL;
im->invalidatefns = NULL;
im->nodata = 0;
if( !(im->filename = im_strdup( NULL, filename )) ) {
im_close( im );
return( NULL );

View File

@ -3,6 +3,8 @@
* 22/5/08
* - from im_open.c, im_openin.c, im_desc_hd.c, im_readhist.c,
* im_openout.c
* 19/3/09
* - block mmaps of nodata images
*/
/*
@ -914,9 +916,9 @@ im__read_header( IMAGE *image )
if( (length = im_file_length( image->fd )) == -1 )
return( -1 );
if( psize > length ) {
im_error( "im_openin", _( "unable to open \"%s\", %s" ),
im_warn( "im_openin", _( "unable to read data for \"%s\", %s" ),
image->filename, _( "file has been truncated" ) );
return( -1 );
image->nodata = 1;
}
/* Set demand style. Allow the most permissive sort.
@ -960,7 +962,7 @@ im_openin( IMAGE *image )
size = (gint64) IM_IMAGE_SIZEOF_LINE( image ) * image->Ysize +
image->sizeof_header;
if( size < im__mmap_limit ) {
if( size < im__mmap_limit && !image->nodata ) {
if( im_mapfile( image ) )
return( -1 );
image->data = image->baseaddr + image->sizeof_header;
@ -981,7 +983,7 @@ im_openin( IMAGE *image )
return( 0 );
}
/* Open, then mmap() read/write. This is old and deprecated API, uuse
/* Open, then mmap() read/write. This is old and deprecated API, use
* im_vips_open() in preference.
*/
int

View File

@ -2,6 +2,8 @@
*
* 30/10/06
* - from region.c
* 19/3/09
* - block mmaps of nodata images
*/
/*
@ -217,6 +219,15 @@ im_window_set( im_window_t *window, int top, int height )
gint64 start, end, pagestart;
size_t length, pagelength;
/* Make sure this image has data.
*/
if( window->im->nodata ) {
im_error( "im_window_set",
_( "unable to read data for \"%s\", %s" ),
window->im->filename, _( "file has been truncated" ) );
return( -1 );
}
/* Calculate start and length for our window.
*/
start = window->im->sizeof_header +