Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/H5Dchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4821,15 +4821,17 @@ H5D__chunk_lock(const H5D_io_info_t H5_ATTR_NDEBUG_UNUSED *io_info, const H5D_ds
size_t chunk_nbytes; /* Length of the chunk in memory */
size_t buf_alloc; /* [Re-]allocated chunk buffer size */

/* Assign above variables and check for overflow */
/* Assign chunk_nbytes and check for overflow */
H5_CHECKED_ASSIGN(chunk_nbytes, size_t, chunk_disk_size, hsize_t);
H5_CHECKED_ASSIGN(buf_alloc, size_t, chunk_disk_size, hsize_t);

/* Ideally we should allocate a buffer at least as large as chunk_size, to give the filter the
* opportunity to avoid doing a realloc when uncompressing. This causes problems now, however,
* and needs more investigation. -NAF */
/* Allocate at MAX(chunk_disk_size, chunk_size) so the buffer is
* large enough for the uncompressed output before filters run.
* This ensures *buf_size accurately reflects the allocation that
* filters receive, avoiding a buffer overflow if any filter writes
* up to *buf_size bytes into *buf. For incompressible chunks
* chunk_disk_size >= chunk_size so buf_alloc stays at chunk_nbytes. */
buf_alloc = (chunk_nbytes < chunk_size) ? chunk_size : chunk_nbytes;

/* Allocate chunk buffer */
if (NULL ==
(chunk = H5D__chunk_mem_alloc(buf_alloc, (udata->new_unfilt_chunk ? old_pline : pline))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
Expand Down
2 changes: 1 addition & 1 deletion src/H5Znbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ H5Z__filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], s
* cd_values[1] stores the flag if true indicating no need to compress
*/
if (cd_values[1])
HGOTO_DONE(*buf_size);
HGOTO_DONE(nbytes);

/* copy a filter parameter to d_nelmts */
d_nelmts = cd_values[2];
Expand Down
2 changes: 1 addition & 1 deletion src/H5Zscaleoffset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ H5Z__filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_valu

/* no need to process data */
if (scale_factor == (int)(cd_values[H5Z_SCALEOFFSET_PARM_SIZE] * 8)) {
ret_value = *buf_size;
ret_value = nbytes;
goto done;
}
minbits = (uint32_t)scale_factor;
Expand Down
Loading