Subject: Fix Segfault during testing
From: Arthur Zamarin <[email-masked]>
Date: Sat, 18 Sep 2021 21:07:45 +0300

decode_usenet_chunks might receive it argument as bytesarray, or
as bytes object, but the C code expects only bytesarray.
Add code, to apply variant for each case, and fail using assert when
both don't apply.

Signed-off-by: Arthur Zamarin <[email-masked]>

--- a/src/sabyenc3.c
+++ b/src/sabyenc3.c
@@ -593,7 +593,13 @@ PyObject* decode_usenet_chunks(PyObject* self, PyObject* args) {
         num_bytes_reserved = 0;
         lp_max = (int)PyList_Size(Py_input_list);
         for(lp = 0; lp < lp_max; lp++) {
-            num_bytes_reserved += (int)PyByteArray_GET_SIZE(PyList_GetItem(Py_input_list, lp));
+            PyObject *temp = PyList_GetItem(Py_input_list, lp);
+            if (PyByteArray_Check(temp))
+                num_bytes_reserved += (int)PyByteArray_GET_SIZE(temp);
+            else if (PyBytes_Check(temp))
+                num_bytes_reserved += (int)PyBytes_GET_SIZE(temp);
+            else
+                assert(PyByteArray_Check(temp) || PyBytes_Check(temp));
         }
     }