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

H5Ocopy may incorrectly copy datasets with variable-length datatype #3335

Closed
jhendersonHDF opened this issue Aug 2, 2023 · 0 comments · Fixed by #3419
Closed

H5Ocopy may incorrectly copy datasets with variable-length datatype #3335

jhendersonHDF opened this issue Aug 2, 2023 · 0 comments · Fixed by #3419
Assignees
Labels
Component - C Library Core C library issues (usually in the src directory) Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub

Comments

@jhendersonHDF
Copy link
Collaborator

Describe the bug
When copying a dataset with a variable-length datatype to a different file (such as when using h5repack), H5Ocopy does not currently account for the possibility of the global heap addresses involved changing between the two files. This can cause the copied datasets in the new file to become unreadable as HDF5 will attempt to read from global heap addresses that may not exist in the new file. Compiling and running the below program will generate a version 1.8 HDF5 file "test.h5" that should contain an unreadable dataset after being repacked with a version of h5repack prior to commit f5c3963.

#include "hdf5.h"

int
main(int argc, char **argv)
{
    hsize_t dims[1]       = {10};
    hsize_t chunk_dims[1] = {5};
    hid_t   fid           = H5I_INVALID_HID;
    hid_t   tid           = H5I_INVALID_HID;
    hid_t   dset_id       = H5I_INVALID_HID;
    hid_t   space_id      = H5I_INVALID_HID;
    hid_t   fapl_id       = H5I_INVALID_HID;
    hid_t   dcpl_id       = H5I_INVALID_HID;

    fapl_id = H5Pcreate(H5P_FILE_ACCESS);
    H5Pset_libver_bounds(fapl_id, H5F_LIBVER_V18, H5F_LIBVER_V18);

    fid = H5Fcreate("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);

    tid = H5Tvlen_create(H5T_NATIVE_INT);

    space_id = H5Screate_simple(1, dims, NULL);

    dcpl_id = H5Pcreate(H5P_DATASET_CREATE);

    hvl_t fill;
    int fillval = 4;
    fill.len = 1;
    fill.p = &fillval;

    H5Pset_fill_value(dcpl_id, tid, &fill);

    dset_id = H5Dcreate2(fid, "dset", tid, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);

    H5Pclose(dcpl_id);
    H5Pclose(fapl_id);
    H5Sclose(space_id);
    H5Tclose(tid);
    H5Dclose(dset_id);
    H5Fclose(fid);

    return 0;
}

Expected behavior
H5Ocopy should be able to translate objects between the global heaps of two different files,
even when the global heap addresses involved aren't the same.

Platform (please complete the following information)
N/A

Additional context
https://forum.hdfgroup.org/t/segmentation-fault-when-using-h5repack-on-netcdf-4-file/11297

@jhendersonHDF jhendersonHDF added Priority - 1. High 🔼 These are important issues that should be resolved in the next release Component - C Library Core C library issues (usually in the src directory) Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub labels Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - C Library Core C library issues (usually in the src directory) Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Bug / Bugfix Please report security issues to [email protected] instead of creating an issue on GitHub
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant