From 66dc7ec0acff10d6f22cb9422bb430018d31722e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 9 May 2017 17:03:16 +0200 Subject: Add missing checks --- libcrystfel/src/image.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'libcrystfel/src') diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index c03b60d8..ef04cbf9 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -424,7 +424,8 @@ static char *cbf_strerr(int e) } -static int unpack_panels(struct image *image, signed int *data, int data_width) +static int unpack_panels(struct image *image, signed int *data, int data_width, + int data_height) { int pi; @@ -471,6 +472,14 @@ static int unpack_panels(struct image *image, signed int *data, int data_width) "with CBF files\n"); } + if ( (p->orig_min_fs + p->w > data_width) + || (p->orig_min_ss + p->h > data_height) ) + { + ERROR("Panel %s is outside range of data in CBF file\n", + p->name); + return 1; + } + for ( ss=0; ssh; ss++ ) { for ( fs=0; fsw; fs++ ) { @@ -574,6 +583,11 @@ static int read_cbf(struct imagefile *f, struct image *image) const char *byteorder; signed int *data; + if ( image->det == NULL ) { + ERROR("read_cbf() needs a geometry\n"); + return 1; + } + if ( cbf_make_handle(&cbfh) ) { ERROR("Failed to allocate CBF handle\n"); return 1; @@ -656,7 +670,7 @@ static int read_cbf(struct imagefile *f, struct image *image) return 1; } - unpack_panels(image, data, dimfast); + unpack_panels(image, data, dimfast, dimmid); free(data); if ( image->beam != NULL ) { -- cgit v1.2.3