[BUG] H5Arename fails unexpectedly

Hello!

HDF5 1.10.*, Windows and GNU/Linux.

To reproduce:

#include "hdf5.h"
#define FILE "test.h5"

int main() {

   hid_t       fcpl_id, file_id, space_id, attr_id;
   herr_t      status;
   int         data = 42;
   int         i;

   fcpl_id = H5Pcreate (H5P_FILE_CREATE);
   status = H5Pset_attr_creation_order (fcpl_id, H5P_CRT_ORDER_TRACKED | 
H5P_CRT_ORDER_INDEXED);
   file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
   status = H5Pclose (fcpl_id);

   for(int i = 0; i <= 9; i++)
     {
       printf("i = %d\n", i);

       space_id = H5Screate (H5S_SCALAR);
       attr_id = H5Acreate2 (file_id, "temp", H5T_INTEL_I32, space_id, 
H5P_DEFAULT, H5P_DEFAULT);
       status = H5Sclose (space_id);
       status = H5Awrite (attr_id, H5T_NATIVE_INT, &data);
       status = H5Aclose (attr_id);

       char str[2];
       snprintf(str, 2, "%d", i);

       status = H5Arename (file_id, "temp", str);
     }

   status = H5Fclose(file_id);
}

This fails with

i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:
   #000: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5A.c line 
1158 in H5Arename(): can't rename attribute
     major: Attribute
     minor: Unable to rename object
   #001: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Oattribute.c 
line 1208 in H5O_attr_rename(): error updating attribute
     major: Attribute
     minor: Can't update object
   #002: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Adense.c 
line 979 in H5A_dense_rename(): unable to add to dense storage
     major: Attribute
     minor: Unable to insert object
   #003: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Adense.c 
line 558 in H5A_dense_insert(): unable to insert record into v2 B-tree
     major: Attribute
     minor: Unable to insert object
   #004: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2.c line 
292 in H5B2_insert(): unable to insert record into B-tree
     major: B-Tree node
     minor: Unable to insert object
   #005: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2int.c 
line 1475 in H5B2__insert(): unable to insert record into B-tree leaf node
     major: B-Tree node
     minor: Unable to insert object
   #006: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2leaf.c 
line 385 in H5B2__insert_leaf(): record is already in B-tree
     major: B-Tree node
     minor: Object already exists
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:
   #000: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5A.c line 
279 in H5Acreate2(): unable to create attribute
     major: Attribute
     minor: Unable to initialize object
   #001: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Aint.c 
line 171 in H5A_create(): attribute already exists
     major: Attribute
     minor: Object already exists
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:
   #000: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5A.c line 
632 in H5Awrite(): not an attribute
     major: Invalid arguments to routine
     minor: Inappropriate type
i = 9
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:
   #000: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5A.c line 
1631 in H5Aclose(): not an attribute
     major: Invalid arguments to routine
     minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:
   #000: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5A.c line 
1158 in H5Arename(): can't rename attribute
     major: Attribute
     minor: Unable to rename object
   #001: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Oattribute.c 
line 1208 in H5O_attr_rename(): error updating attribute
     major: Attribute
     minor: Can't update object
   #002: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Adense.c 
line 979 in H5A_dense_rename(): unable to add to dense storage
     major: Attribute
     minor: Unable to insert object
   #003: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5Adense.c 
line 558 in H5A_dense_insert(): unable to insert record into v2 B-tree
     major: Attribute
     minor: Unable to insert object
   #004: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2.c line 
292 in H5B2_insert(): unable to insert record into B-tree
     major: B-Tree node
     minor: Unable to insert object
   #005: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2int.c 
line 1475 in H5B2__insert(): unable to insert record into B-tree leaf node
     major: B-Tree node
     minor: Unable to insert object
   #006: 
C:\autotest\hdf5110-StdRelease-code-10vs14\build\hdfsrc\src\H5B2leaf.c 
line 385 in H5B2__insert_leaf(): record is already in B-tree
     major: B-Tree node
     minor: Object already exists

Please consider critical: H5Acreate-then-H5Arename flow is used in e.g. h5py

Best wishes,
Andrey Paramonov

Andrey,

Thank you for reporting the issue! I confirmed the same behavior with the latest HDF5 1.10.3 release.

For your reference - I entered HDFFV-10579.

Elena

Iā€™m wondering if there has been any progress on this front. We are hitting this bug with a few downstream projects

According to our issue board that was fixed in April of 2019. And should have been in the releases afterwards.
I will check to verify that the fix is in the maintenance releases.

1 Like

Thank you for the fast reply.

I believe we narrowed it down to a different bug that seemed related.

We opened https://github.com/HDFGroup/hdf5/issues/1388