blob: 1a80d5f13da85c4c601648bc441afe3a01e7ca0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
From: Arthur Zamarin <arthurzam@gmail.com>
Date: Sat, 18 Sep 2021 21:07:45 +0300
Subject: Fix Segfault during testing
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 <arthurzam@gmail.com>
--- 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));
}
}
|