cgohlke / imagecodecs

Image transformation, compression, and decompression codecs
https://pypi.org/project/imagecodecs
BSD 3-Clause "New" or "Revised" License
121 stars 24 forks source link

Possible issue with lzf codec #103

Closed sharkinsspatial closed 5 months ago

sharkinsspatial commented 5 months ago

Environment

Python 3.11.8 liblzf 3.6 imagecodecs 2024.6.1

Expected Behavior

lzf_encode and lzf_decode can compress and decompress a numpy array.

Actual Behavior

lzf_decode throws an error with float data

Example Code

import imagecodecs
import numpy as np

array = np.arange(10, dtype=np.float32)

compressed_array = imagecodecs.lzf_encode(array)

decompressed_array = imagecodecs.lzf_decode(compressed_array)

Returns

File "imagecodecs/_lzf.pyx", line 162, in imagecodecs._lzf.lzf_decode
imagecodecs._lzf.LzfError: lzf_decompress returned 0
cgohlke commented 5 months ago

If lzf_encode and lzf_decode are not used with header=True, the output size has to be passed to lzf_decode, for example lzf_decode(compressed_array, out=array.nbytes).

The error handling should be improved, including checking the errno variable...

cgohlke commented 5 months ago

The next version will check errno and raise LzfError: lzf_decompress detected the output buffer is not large enough to hold the decompressed data in such cases. The default output buffer size is raised to 8 times the input size.

cgohlke commented 2 months ago

Fixed in imagecodecs 2024.9.22.