Skip to content

Commit

Permalink
Merge pull request python#29 from python-lz4/block_fixes
Browse files Browse the repository at this point in the history
Allow zero length data to be passed to block compress
  • Loading branch information
jonathanunderwood authored May 13, 2017
2 parents 6b548e8 + 96f2a89 commit 1b60148
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lz4/block/_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
return NULL;
}

if (source_size <= 0) {
PyErr_Format(PyExc_ValueError, "Input source data size invalid: %d bytes", source_size);
return NULL;
}

if (!strncmp (mode, "default", sizeof ("default")))
{
comp = DEFAULT;
Expand Down Expand Up @@ -258,7 +253,7 @@ decompress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
source_size -= hdr_size;
}

if (dest_size <= 0 || dest_size > PY_SSIZE_T_MAX)
if (dest_size < 0 || dest_size > PY_SSIZE_T_MAX)
{
PyErr_Format (PyExc_ValueError, "Invalid size in header: 0x%zu",
dest_size);
Expand Down
4 changes: 4 additions & 0 deletions tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class TestLZ4Block(unittest.TestCase):

def test_empty_string(self):
DATA = b''
self.assertEqual(DATA, lz4.block.decompress(lz4.block.compress(DATA)))

def test_random(self):
DATA = os.urandom(128 * 1024) # Read 128kb
self.assertEqual(DATA, lz4.block.decompress(lz4.block.compress(DATA)))
Expand Down

0 comments on commit 1b60148

Please sign in to comment.