From 938451f0c83fdbb1de97e2a27b4bdecf218e37ed Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 20 Oct 2021 12:13:14 +0200 Subject: image_hdf5_read_peaks_cxi: Make sure array is big enough --- libcrystfel/src/image-hdf5.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 129fb62c..8ec76ee6 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -1153,7 +1153,8 @@ static int read_peak_count(hid_t fh, char *path, int line, } -static float *read_peak_line(hid_t fh, char *path, int line) +static float *read_peak_line(hid_t fh, char *path, int line, + int num_peaks) { hid_t dh, sh, mh; @@ -1196,6 +1197,15 @@ static float *read_peak_line(hid_t fh, char *path, int line) return NULL; } + /* NB The array might be bigger - Cheetah allocates in blocks of 2048 */ + if ( size[1] < num_peaks ) { + ERROR("Data block %s is too small for the specified number of " + "peaks (has %i, expected %i)\n", path, size[1], num_peaks); + H5Sclose(sh); + H5Dclose(dh); + return NULL; + } + offset[0] = line; offset[1] = 0; count[0] = 1; @@ -1315,19 +1325,19 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl, return NULL; } - buf_x = read_peak_line(fh, path_x, line); + buf_x = read_peak_line(fh, path_x, line, num_peaks); if ( buf_x == NULL ) { close_hdf5(fh); return NULL; } - buf_y = read_peak_line(fh, path_y, line); + buf_y = read_peak_line(fh, path_y, line, num_peaks); if ( buf_y == NULL ) { close_hdf5(fh); return NULL; } - buf_i = read_peak_line(fh, path_i, line); + buf_i = read_peak_line(fh, path_i, line, num_peaks); if ( buf_i == NULL ) { close_hdf5(fh); return NULL; -- cgit v1.2.3