Skip to content

Commit 1b60148

Browse files
Merge pull request python#29 from python-lz4/block_fixes
Allow zero length data to be passed to block compress
2 parents 6b548e8 + 96f2a89 commit 1b60148

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lz4/block/_block.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
121121
return NULL;
122122
}
123123

124-
if (source_size <= 0) {
125-
PyErr_Format(PyExc_ValueError, "Input source data size invalid: %d bytes", source_size);
126-
return NULL;
127-
}
128-
129124
if (!strncmp (mode, "default", sizeof ("default")))
130125
{
131126
comp = DEFAULT;
@@ -258,7 +253,7 @@ decompress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
258253
source_size -= hdr_size;
259254
}
260255

261-
if (dest_size <= 0 || dest_size > PY_SSIZE_T_MAX)
256+
if (dest_size < 0 || dest_size > PY_SSIZE_T_MAX)
262257
{
263258
PyErr_Format (PyExc_ValueError, "Invalid size in header: 0x%zu",
264259
dest_size);

tests/test_block.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
class TestLZ4Block(unittest.TestCase):
1010

11+
def test_empty_string(self):
12+
DATA = b''
13+
self.assertEqual(DATA, lz4.block.decompress(lz4.block.compress(DATA)))
14+
1115
def test_random(self):
1216
DATA = os.urandom(128 * 1024) # Read 128kb
1317
self.assertEqual(DATA, lz4.block.decompress(lz4.block.compress(DATA)))

0 commit comments

Comments
 (0)