Skip to content

Commit 31e8beb

Browse files
committed
protect users from going oob with tile sizes
1 parent 4b255ff commit 31e8beb

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/silvimetric/resources/storage.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,26 @@ def create(config: StorageConfig, ctx: tiledb.Ctx = None):
8787
(config.root.maxy - config.root.miny) / float(config.resolution)
8888
)
8989

90+
# protect user from out of bounds errors
91+
xsize = min(config.xsize, xi-1)
92+
ysize = min(config.ysize, yi-1)
93+
if xsize < config.xsize:
94+
config.log.warning(f'X Tile size lowered to {xsize}')
95+
if ysize < config.ysize:
96+
config.log.warning(f'Y Tile size lowered to {ysize}')
97+
9098
dim_row = tiledb.Dim(
9199
name='X',
92100
domain=(0, xi),
93101
dtype=np.uint64,
94-
tile=config.xsize,
102+
tile=xsize,
95103
filters=tiledb.FilterList([tiledb.ZstdFilter()]),
96104
)
97105
dim_col = tiledb.Dim(
98106
name='Y',
99107
domain=(0, yi),
100108
dtype=np.uint64,
101-
tile=config.ysize,
109+
tile=ysize,
102110
filters=tiledb.FilterList([tiledb.ZstdFilter()]),
103111
)
104112
domain = tiledb.Domain(dim_row, dim_col)

tests/test_storage.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44
import os
55
import copy
6-
import datetime
76

87
from silvimetric import (
98
Storage,
@@ -93,6 +92,32 @@ def test_metric_dependencies(
9392

9493
ms[0].dependencies = []
9594

95+
def test_oob_storage(
96+
self,
97+
tmp_path_factory,
98+
metrics,
99+
crs,
100+
resolution,
101+
attrs,
102+
bounds,
103+
):
104+
ms = copy.deepcopy(metrics)
105+
path = tmp_path_factory.mktemp('test_tdb')
106+
p = os.path.abspath(path)
107+
108+
sc = StorageConfig(
109+
tdb_dir=p,
110+
crs=crs,
111+
resolution=resolution,
112+
attrs=attrs,
113+
metrics=ms,
114+
root=bounds,
115+
xsize=1000,
116+
ysize=1000
117+
)
118+
119+
Storage.create(sc)
120+
96121
def test_metrics(self, storage: Storage):
97122
m_list = storage.get_metrics()
98123
a_list = storage.get_attributes()

0 commit comments

Comments
 (0)