Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix valgrind warning about write of uninitialized bytes in ScaleOffse… #3390

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
8 changes: 7 additions & 1 deletion src/H5Zscaleoffset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,9 @@ H5Z__filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_valu
}
/* output; compress */
else {
size_t used_bytes;
size_t unused_bytes;

assert(nbytes == d_nelmts * p.size);

/* before preprocess, convert to memory endianness order if needed */
Expand Down Expand Up @@ -1334,7 +1337,10 @@ H5Z__filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_valu
/* (Looks like an error in the original determination of how many
* bytes would be needed for parameters. - QAK, 2010/08/19)
*/
memset(outbuf + 13, 0, (size_t)8);
used_bytes = 4 + 1 + sizeof(unsigned long long);
assert(used_bytes <= size_out);
unused_bytes = size_out - used_bytes;
memset(outbuf + 13, 0, unused_bytes);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 1316 above implies that there may be an extra byte in the buffer at times. This memset was assuming the buffer is only 21 bytes, but I encountered a valgrind warning where the buffer is 22 bytes and so the last byte in the buffer was uninitialized when written to the file:

==32533== Syscall param pwritev(vector[2]) points to uninitialised byte(s)
==32533==    at 0x52CA758: pwritev (in /lib64/libc-2.37.so)
==32533==    by 0x86E4E45: mca_fbtl_posix_pwritev_generic (fbtl_posix_pwritev.c:290)
==32533==    by 0x86E435A: mca_fbtl_posix_pwritev (fbtl_posix_pwritev.c:74)
==32533==    by 0x8156100: mca_common_ompio_file_write (common_ompio_file_write.c:154)
==32533==    by 0x81632CD: mca_fcoll_individual_file_write_all (fcoll_individual_file_write_all.c:39)
==32533==    by 0x8156B1B: mca_common_ompio_file_write_all (common_ompio_file_write.c:431)
==32533==    by 0x8156B90: mca_common_ompio_file_write_at_all (common_ompio_file_write.c:452)
==32533==    by 0x80EC55D: mca_io_ompio_file_write_at_all (io_ompio_file_write.c:174)
==32533==    by 0x507DB07: PMPI_File_write_at_all (pfile_write_at_all.c:75)
==32533==    by 0x4A5AC63: H5FD__mpio_write (H5FDmpio.c:1587)
==32533==    by 0x4A49832: H5FD_write (H5FDint.c:308)
==32533==    by 0x4A0F230: H5F__accum_write (H5Faccum.c:820)
==32533==  Address 0x8c7add5 is 21 bytes inside a block of size 22 alloc'd
==32533==    at 0x48427B4: malloc (vg_replace_malloc.c:393)
==32533==    by 0x4B3E57A: H5MM_malloc (H5MM.c:80)
==32533==    by 0x4D467FF: H5Z__filter_scaleoffset (H5Zscaleoffset.c:1316)
==32533==    by 0x4D3CEA1: H5Z_pipeline (H5Z.c:1423)
==32533==    by 0x4989AC6: H5D__chunk_allocate (H5Dchunk.c:4978)
==32533==    by 0x49A478E: H5D__init_storage (H5Dint.c:2443)
==32533==    by 0x49AA641: H5D__alloc_storage (H5Dint.c:2353)
==32533==    by 0x49B37E8: H5D__layout_oh_create (H5Dlayout.c:479)
==32533==    by 0x49A3540: H5D__update_oh_info (H5Dint.c:978)
==32533==    by 0x49A62D5: H5D__create (H5Dint.c:1299)
==32533==    by 0x49C6067: H5O__dset_create (H5Doh.c:272)
==32533==    by 0x4B8163C: H5O_obj_create (H5Oint.c:2347)


/* special case: minbits equal to full precision */
if (minbits == p.size * 8) {
Expand Down