diff options
author | Thomas White <taw@physics.org> | 2021-10-20 12:13:14 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-10-20 12:13:14 +0200 |
commit | 938451f0c83fdbb1de97e2a27b4bdecf218e37ed (patch) | |
tree | 098fc0219a70ae10ed7ea6be4e786acfeb0768af | |
parent | 9660ab57f5f95ed9b4dfec7f41ec5a553e2ed859 (diff) |
image_hdf5_read_peaks_cxi: Make sure array is big enough
-rw-r--r-- | libcrystfel/src/image-hdf5.c | 18 |
1 files changed, 14 insertions, 4 deletions
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; |