# Corrupted file due to shutdown

**URL:** <https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658>\
**Category:** HDF5 Library\
**Created:** [April 11, 2022, 5:51pm UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658 "2022-04-11T17:51:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [April 11, 2022, 5:51pm UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/1 "2022-04-11T17:51:23Z")

</div>

Hello!

I have a problem with a HDF5 file created with h5py. I have the suspicion that the process writing to the file was killed.

**Problem**  
I have a HDF5 file created with h5py. Unfortunately I cannot read the data within because I get several errors when trying to access the data with their path:

- Unable to open object (address of object past end of allocation)
- Unable to get group info (addr overflow, addr = 44103764, size = 544, eoa = 2048)

**Additional Info**  
I suspect the process writing to the file was killed (thus the file not properly closed).  
System: Ubuntu 20.04  
hdf5-utils info:  
$ h5dump file.hd5  
h5dump error: internal error (file …/…/…/…/…/tools/src/h5dump/h5dump.c:line 1493)  
$ h5debug file.hd5  
Reading signature at address 0 (rel)  
File Super Block…  
File name (as opened): file.hd5  
File name (after resolving symlinks): file.hd5  
File access flags 0x00000000  
File open reference count: 1  
Address of super block: 0 (abs)  
Size of userblock: 0 bytes  
Superblock version number: 0  
Free list version number: 0  
Root group symbol table entry version number: 0  
Shared header version number: 0  
Size of file offsets (haddr\_t type): 8 bytes  
Size of file lengths (hsize\_t type): 8 bytes  
Symbol table leaf node 1/2 rank: 4  
Symbol table internal node 1/2 rank: 16  
Indexed storage internal node 1/2 rank: 32  
File status flags: 0x01  
Superblock extension address: UNDEF (rel)  
Shared object header message table address: UNDEF (rel)  
Shared object header message version number: 0  
Number of shared object header message indexes: 0  
Address of driver information block: UNDEF (rel)  
Root group symbol table entry:  
Name offset into private heap: 0  
Object header address: 96  
Cache info type: Symbol Table  
Cached entry information:  
B-tree address: 136  
Heap address: 680

**Attempt**  
So I extended _eoa_ with: `h5clear --increment file.hd5`

Now I get the following error (only this one).  
`Link iteration failed (bad local heap signature)`

**Reconstructing**  
Is it possible to reconstruct the data in the file?  
I know exactly what the single datasets are. (size and type).  
Is it possible to index the datasets differently than with their name. Maybe with the memory offset from their parent.

_I would greatly appreciate any help. **Thank you!** _

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [April 12, 2022, 12:28am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/2 "2022-04-12T00:28:55Z")

</div>

What does

```auto
strings -t d file.hd5

```

show?

G.

---

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [May 2, 2022, 9:29am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/3 "2022-05-02T09:29:59Z")

</div>

Thank you for the answer and sorry for the late reply (I was ill).

The command you suggested seems to be able to read the file. It does not throw any exceptions and puts out what seems to be memory addresses and its contents. Also it seems to be able to show the structure. I had to zip the output to be able to upload it ([strings.zip](https://hdf-discourse-1.s3.amazonaws.com/original/2X/e/e6039a028cf0322bb7a84a7d65d233606d85421f.zip) (8.0 MB)).

The structure of the file should be as follows:

> `thermal_evo_2/`  
> `├─ 1/`  
> `│ ├─ Float Array 32x32`  
> `├─ 2/`  
> `│ ├─ Float Array 32x32`  
> `├─ ...`  
> `├─ n/`  
> `│ ├─ Float Array 32x32`  
> `thermal_evo_1/`  
> `├─ 1/`  
> `│ ├─ Float Array 32x32`  
> `├─ 2/`  
> `│ ├─ Float Array 32x32`  
> `├─ ...`  
> `├─ n/`  
> `│ ├─ Float Array 32x32`  
> `thermal_cts_1/`  
> `├─ 1/`  
> `│ ├─ Float Array 15x36`  
> `├─ 2/`  
> `│ ├─ Float Array 15x36`  
> `├─ ...`  
> `├─ m/`  
> `│ ├─ Float Array 15x36`

Christian

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [May 4, 2022, 11:52am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/4 "2022-05-04T11:52:55Z")

</div>

Christian, glad to have you back. We hope you are doing better.

I took a quick peek and there is maybe good news and not-so-good news. The underlying HDF5 file appears to be around 200 MB in size (correct? otherwise there might be a lot of wasted space…). The two keywords that stand out and appear with some frequency are `deflate` (41,049) and `TREE` (41,619). Assuming your groups are not compressed, that suggests you are looking at least at 41,049 chunked, Gzip compressed datasets and 570 groups. (Since the dataset dimensions are so small `32x32`, etc., that’s a bit of overkill, but we are where we are.) Apart from the dataset dimensions, do we know the size of those chunks? Maybe there is only one chunk per dataset? We can work without that information because we know that the size of a decompressed chunk must be divisible by the size of your floating-point numbers (4,8, ?), and we presumably know the endianness. To get at the actual data, we must:

1. Traverse the B-trees corresponding to those chunked datasets (to understand where in the dataset a chunk belongs)
2. Retrieve the compressed chunks located in the leaves of those trees
3. Decompress them
4. Recast them as floating-point arrays

There are a few things we don’t know, and that we may not be able to recover.

1. We may not be able to establish with certainty which dataset is which, i.e., where in the corrupted (?) group structure it was located originally.
2. If there are other datasets such as compact or contiguous datasets, we’ll have to hunt them down separately.

I made it sound easy, but this is mostly _blood, sweat, and tears_ (aka, forensics) If the data is that important, you should either try it yourself or find someone who does it for you.

Best, G.

---

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [May 5, 2022, 9:36am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/5 "2022-05-05T09:36:19Z")

</div>

Thank you! That does sound like a lot of work. Unfortunately the data is quite important. Since you mentioned finding someone to do it. Would there be a possibility to have someone from HDF Group do the forensics. I would guess since the expertise lies with you this would be much faster. If yes, what would be the hourly rate?

For now let me try an answer your questions and remarks.

- Yes, the currupted HDF5 file has about 220 MB

- I do not think that the groups are compressed. I only use compression on data set level. I use h5py to create the files.

- I think there should only be 3 groups. _/thermal\_evo\_1_, _/thermal\_evo\_2_, _/thermal\_cts\_1_ with a lot of data sets in each one. The structure is that way because every data set represents an image.

- Do we know the chunk size… Well according to the h5py docs my setting performs auto-chunking. So I guess no. BUT I do have perfectly fine data files with the same structure but, obviously, different data. Might that help?

- If it is not possible to establish which data set is which it does not matter if it is possible to regain the _ts_ attribute of that data set.

- How would I go about and traverse the B-trees? Is there an example or documentation? Or is the HDF source code open source? I guess looking at _h5dump_ would make things a lot easier.

Thanks again,  
Christian

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [May 5, 2022, 2:48pm UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/6 "2022-05-05T14:48:38Z")

</div>

> [@christian.helmel](#):
>
> I think there should only be 3 groups.

Yes, the link names for those can be seen on the root group’s local heap at (decimal) offsets 720, 736, 752.

> [@christian.helmel](#):
>
> Do we know the chunk size…

No problem. If the data layout messages are intact, we can get the chunk size from there.

> [@christian.helmel](#):
>
> If it is not possible to establish which data set is which it does not matter if it is possible to regain the _ts_ attribute of that data set.

Good to know. What’s the datatype of these attributes? Is the dataspace scalar?

> [@christian.helmel](#):
>
> How would I go about and traverse the B-trees? Is there an example or documentation? Or is the HDF source code open source?

The file format specification can be found [here](https://docs.hdfgroup.org/hdf5/develop/_f_m_t3.html). Yes, HDF5 is open source, always was and always will be, & the code can be found [here](https://github.com/HDFGroup/hdf5). There are a few tools such as `h5debug`, `h5check`, and there is even a [small tutorial on the file format](https://docs.hdfgroup.org/hdf5/develop/_f_m_t_d_i_s_c.html).

> [@christian.helmel](#):
>
> Would there be a possibility to have someone from HDF Group do the forensics. I would guess since the expertise lies with you this would be much faster. If yes, what would be the hourly rate?

Yes, and we’ll contact you.

Best, G.

---

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [May 9, 2022, 6:11am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/7 "2022-05-09T06:11:59Z")

</div>

> [@gheber](#):
>
> Good to know. What’s the datatype of these attributes? Is the dataspace scalar?

There is one attribute per data set named _ts_. The data type is a scalar float64.

> [@gheber](#):
>
> The file format specification can be found [here](https://docs.hdfgroup.org/hdf5/develop/_f_m_t3.html). Yes, HDF5 is open source, always was and always will be, & the code can be found [here](https://github.com/HDFGroup/hdf5). There are a few tools such as `h5debug`, `h5check`, and there is even a [small tutorial on the file format](https://docs.hdfgroup.org/hdf5/develop/_f_m_t_d_i_s_c.html).

Thank you for the pointers. So far I was able to iterate the B-Tree to where I can read the SymbolTableEntries of the 3 main groups and their names.

> [@gheber](#):
>
> Yes, and we’ll contact you.

Thank you.

---

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [May 12, 2022, 3:31pm UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/8 "2022-05-12T15:31:28Z")

</div>

Thank you for all your help and all of the very useful pointers. I managed to recover the data in the file. I did not get all the names of the datasets but with the mentioned attribute i was able to reconstruct the data.

Thank you and all the best,  
Christian

---

<div class="post-metadata">

**Author:** ![smith.alex1848](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@smith.alex1848](https://forum.hdfgroup.org/u/smith.alex1848)\
**Post date:** [February 7, 2025, 7:55pm UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/9 "2025-02-07T19:55:37Z")

</div>

Hey Christian, I know this is a few years old now, but I am wondering if you can give any details on what you did to recover your data? I am now facing a similar issue. Thanks!

---

<div class="post-metadata">

**Author:** ![christian.helmel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@christian.helmel](https://forum.hdfgroup.org/u/christian.helmel)\
**Post date:** [March 7, 2025, 9:49am UTC](https://forum.hdfgroup.org/t/corrupted-file-due-to-shutdown/9658/10 "2025-03-07T09:49:54Z")

</div>

Hello Alex!

I did exactly what was talked about in this conversation. I used the h5py library to manually traverse the BTreeNodes in the hdf5 file. With my knowledge of how the file must have been structured and this approach I was able to re gain the corrupted data file.

This was quite some time ago but this was the approach.

I hope that helps. Regards!
