Skip to content

Commit

Permalink
Prevent a crash when accessing block shapes of an HDF5 file (#2859)
Browse files Browse the repository at this point in the history
Resolves #2855
  • Loading branch information
sgillies committed Jun 26, 2023
1 parent 0ee2b61 commit e2dcbce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGES.txt
@@ -1,9 +1,10 @@
Changes
=======

1.3.8 (TBD)
-----------
1.3.8 (2023-06-26)
------------------

- Prevent a crash when accessing the block shapes of a multidataset HDF5 file (#).
- Add a workaround for a GDAL multithreading bug introduced in 3.6.0 (#2851).

1.3.7 (2023-05-22)
Expand Down
9 changes: 6 additions & 3 deletions rasterio/_base.pyx
Expand Up @@ -518,8 +518,8 @@ cdef class DatasetBase:
list
"""
cdef GDALRasterBandH band = NULL
cdef int xsize
cdef int ysize
cdef int xsize = 0
cdef int ysize = 0

if self._block_shapes is None:
self._block_shapes = []
Expand Down Expand Up @@ -1031,8 +1031,11 @@ cdef class DatasetBase:
blockxsize=self.block_shapes[0][1],
blockysize=self.block_shapes[0][0],
tiled=True)
else:
elif len(self.block_shapes) > 0:
m.update(blockysize=self.block_shapes[0][0], tiled=False)
else:
m.update(tiled=False)

if self.compression:
m['compress'] = self.compression.name
if self.interleaving:
Expand Down
Binary file added tests/data/two-subs.h5
Binary file not shown.
19 changes: 14 additions & 5 deletions tests/test_subdatasets.py
Expand Up @@ -3,15 +3,24 @@
import rasterio

with rasterio.Env() as env:
HAVE_NETCDF = 'NetCDF' in env.drivers().keys()
HAVE_NETCDF = "NetCDF" in env.drivers().keys()
HAVE_HDF5 = "HDF5" in env.drivers().keys()


@pytest.mark.skipif(not HAVE_NETCDF,
reason="GDAL not compiled with NetCDF driver.")
@pytest.mark.skipif(not HAVE_NETCDF, reason="GDAL not compiled with NetCDF driver.")
def test_subdatasets():
"""Get subdataset names and descriptions"""
with rasterio.open('netcdf:tests/data/RGB.nc') as src:
with rasterio.open("netcdf:tests/data/RGB.nc") as src:
subs = src.subdatasets
assert len(subs) == 3
for name in subs:
assert name.startswith('netcdf')
assert name.startswith("netcdf")


@pytest.mark.skipif(not HAVE_HDF5, reason="GDAL not compiled with HDF5 driver.")
def test_subdatasets_h5():
"""Get subdataset names and descriptions"""
with rasterio.open("tests/data/two-subs.h5") as src:
subs = src.subdatasets
assert len(subs) == 2
assert src.profile["count"] == 0

0 comments on commit e2dcbce

Please sign in to comment.