Skip to content

Commit 5ecc9bb

Browse files
authored
Merge branch 'main' into mkitti-multi-frame-zstd-clean
2 parents 4766a06 + 878d2b3 commit 5ecc9bb

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

.github/workflows/ci-i386.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Tests on i386
2+
3+
on: [push, pull_request]
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
build-i386:
11+
runs-on: ubuntu-latest
12+
13+
defaults:
14+
run:
15+
shell: bash -el {0}
16+
17+
steps:
18+
- name: Checkout source
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
fetch-depth: 0 # required for version resolution
23+
24+
- name: Setup Alpine Linux environment
25+
uses: jirutka/[email protected]
26+
with:
27+
arch: x86
28+
packages: >
29+
build-base
30+
python3
31+
python3-dev
32+
git
33+
py3-pip
34+
py3-pytest
35+
uv
36+
meson
37+
pkgconf
38+
py3-numpy
39+
py3-numpy-dev
40+
zstd
41+
42+
- name: Install numcodecs
43+
run: |
44+
export DISABLE_NUMCODECS_AVX2=""
45+
uv venv
46+
uv pip install -v -e .[test,test_extras,msgpack,crc32c]
47+
shell: alpine.sh {0}
48+
49+
50+
- name: Install zarr-python
51+
# Since zarr v3 requires numpy >= 1.25, on Python 3.11 leave it out
52+
# so we can have some tests of our minimum version of numpy (1.24)
53+
if: matrix.python-version != '3.11'
54+
run: uv add zarr>=3
55+
shell: alpine.sh {0}
56+
57+
58+
- name: List installed packages
59+
run: uv pip list
60+
shell: alpine.sh {0}
61+
62+
- name: Run tests
63+
run: uv run pytest -v
64+
shell: alpine.sh {0}

numcodecs/zstd.pyx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ from .abc import Codec
1515

1616
from libc.stdlib cimport malloc, realloc, free
1717

18+
cdef extern from "stdint.h":
19+
cdef size_t SIZE_MAX
20+
1821
cdef extern from "zstd.h":
1922

2023
unsigned ZSTD_versionNumber() nogil
@@ -204,8 +207,8 @@ def decompress(source, dest=None):
204207
Py_buffer* dest_pb
205208
char* dest_ptr
206209
size_t source_size, dest_size, decompressed_size
207-
size_t nbytes, cbytes, blocksize
208210
size_t dest_nbytes
211+
unsigned long long content_size
209212

210213
# obtain source memoryview
211214
source_mv = ensure_continguous_memoryview(source)
@@ -216,18 +219,24 @@ def decompress(source, dest=None):
216219
source_size = source_pb.len
217220

218221
try:
219-
220-
# determine uncompressed size
222+
# determine uncompressed size using unsigned long long for full range
221223
try:
222-
dest_size = findTotalContentSize(source_ptr, source_size)
224+
content_size = findTotalContentSize(source_ptr, source_size)
223225
except RuntimeError:
224226
raise RuntimeError('Zstd decompression error: invalid input data')
225227

226-
if dest_size == 0 or dest_size == ZSTD_CONTENTSIZE_ERROR:
228+
if content_size == ZSTD_CONTENTSIZE_UNKNOWN and dest is None:
229+
return stream_decompress(source_pb)
230+
elif content_size == ZSTD_CONTENTSIZE_UNKNOWN:
231+
# dest is not None
232+
# set dest_size based on dest
233+
pass
234+
elif content_size == ZSTD_CONTENTSIZE_ERROR or content_size == 0:
227235
raise RuntimeError('Zstd decompression error: invalid input data')
236+
elif content_size > (<unsigned long long>SIZE_MAX):
237+
raise RuntimeError('Zstd decompression error: content size too large for platform')
228238

229-
if dest_size == ZSTD_CONTENTSIZE_UNKNOWN and dest is None:
230-
return stream_decompress(source_pb)
239+
dest_size = <size_t>content_size
231240

232241
# setup destination buffer
233242
if dest is None:
@@ -242,7 +251,7 @@ def decompress(source, dest=None):
242251
dest_ptr = <char*>dest_pb.buf
243252
dest_nbytes = dest_pb.len
244253

245-
if dest_size == ZSTD_CONTENTSIZE_UNKNOWN:
254+
if content_size == ZSTD_CONTENTSIZE_UNKNOWN:
246255
dest_size = dest_nbytes
247256

248257
# validate output buffer

0 commit comments

Comments
 (0)