Apollo3zehn / PureHDF

A pure .NET library that makes reading and writing of HDF5 files (groups, datasets, attributes, ...) very easy.
MIT License
47 stars 16 forks source link

Index out of range when trying to read dataset of VariableLength #28

Closed neroarth94 closed 1 year ago

neroarth94 commented 1 year ago

Hi, I am trying to read a HDF5 file and came across an issue when trying to read a dataset that is VariableLength type. To read the dataset, i just use the code: var data = dataset.ReadString();

but it fails with the following exception:

 System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. 
 (Parameter 'index')
    at PureHDF.H5ReadUtils.ReadString(H5Context context, DatatypeMessage datatype, Span`1 data, String[] result) in 
 /home/runner/work/PureHDF/PureHDF/src/PureHDF/Utils/H5ReadUtils.cs:line 293
    at PureHDF.H5Dataset.ReadString(Selection fileSelection, Selection memorySelection, UInt64[] memoryDims, 
 H5DatasetAccess datasetAccess) in /home/runner/work/PureHDF/PureHDF/src/PureHDF/API/H5Dataset.cs:line 270

It works fine if I read dataset with String type. May I know what else I need to specify to be able to read the VariableLength? The attached screenshot is an example of the dataset properties image

Thank you.

Apollo3zehn commented 1 year ago

HI, could you please provide a small sample file? This looks like a bug. Thank you!

neroarth94 commented 1 year ago

Hi @Apollo3zehn , the sample file as below. Github doesn't let me upload file with hdf5 extension so i need to zip it example.zip

Apollo3zehn commented 1 year ago

Thank you. I found the issue. How has this file been created? Did you delete any objects after file creation? I think the problem is easy to solve on my side but I would first like to understand how such an internal file structure is produced :-)

neroarth94 commented 1 year ago

Steps to reproduce:

  1. Open HDFView
  2. Create a new hdf5 file
  3. Create new dataset with variable length (VLEN_STRING) as shown in attached screenshot
  4. it would catch the exception when reading variable length

I did not delete any objects or have any further steps other than the above Sorry but may I know when will you roll out the fix because I would like to proceed with my work. thank you~

image

Apollo3zehn commented 1 year ago

It is fixed now (I hope :-)). I only have access to my mobile phone right now and tried to fix it using GitHub Code Spaces. My limited test showed that the exception does not occur anymore. Release v1.0.0-alpha.24 contains the fix.