Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: correct PyArg_ParseTuple format and non-NULL return with excepti…
…on in stream module

- Fix _compress_bound: format "OI" expects (PyObject*, unsigned int) but only
  &input_size is provided. The "O" writes a PyObject* into a uint32_t —
  type mismatch and memory corruption on every call. Change to "I" to match
  the identical _input_bound function at line 1091.

- Fix _compress: when update_context_after_process fails, PyErr_Format sets
  an exception but goto exit_now returns the already-created py_dest (non-NULL).
  This violates the Python/C API contract (returning a result with an exception
  set), causing SystemError. Clear py_dest before the goto.

Found using cext-review-toolkit (https://github.com/devdanzin/cext-review-toolkit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
devdanzin and claude committed Apr 1, 2026
commit 0957fe173e3ca994d6388707068a4f7410ada910
3 changes: 2 additions & 1 deletion lz4/stream/_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ _compress_bound (PyObject * Py_UNUSED (self), PyObject * args)
/* Positional arguments: input_size
* Keyword arguments : none
*/
if (!PyArg_ParseTuple (args, "OI", &input_size))
if (!PyArg_ParseTuple (args, "I", &input_size))
{
goto exit_now;
}
Expand Down Expand Up @@ -1211,6 +1211,7 @@ _compress (PyObject * Py_UNUSED (self), PyObject * args)

if (context->strategy.ops->update_context_after_process (context) != 0)
{
Py_CLEAR (py_dest);
PyErr_Format (PyExc_RuntimeError, "Internal error");
goto exit_now;
}
Expand Down
Loading