Skip to content

Commit 353da45

Browse files
committed
[GR-54236] Avoid direct slice access in cffi
PullRequest: graalpython/3343
2 parents 1417114 + 0d4fb3d commit 353da45

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

graalpython/lib-graalpython/patches/cffi/cffi-1.15.1.patch

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
2+
index b9618bd..fbfd82b 100644
3+
--- a/c/_cffi_backend.c
4+
+++ b/c/_cffi_backend.c
5+
@@ -2507,19 +2507,22 @@ _cdata_getslicearg(CDataObject *cd, PySliceObject *slice, Py_ssize_t bounds[])
6+
Py_ssize_t start, stop;
7+
CTypeDescrObject *ct;
8+
9+
- start = PyInt_AsSsize_t(slice->start);
10+
+ PyObject* slicestart = PySlice_Start(slice);
11+
+ start = PyInt_AsSsize_t(slicestart);
12+
if (start == -1 && PyErr_Occurred()) {
13+
- if (slice->start == Py_None)
14+
+ if (slicestart == Py_None)
15+
PyErr_SetString(PyExc_IndexError, "slice start must be specified");
16+
return NULL;
17+
}
18+
- stop = PyInt_AsSsize_t(slice->stop);
19+
+ PyObject* slicestop = PySlice_Stop(slice);
20+
+ stop = PyInt_AsSsize_t(slicestop);
21+
if (stop == -1 && PyErr_Occurred()) {
22+
- if (slice->stop == Py_None)
23+
+ if (slicestop == Py_None)
24+
PyErr_SetString(PyExc_IndexError, "slice stop must be specified");
25+
return NULL;
26+
}
27+
- if (slice->step != Py_None) {
28+
+ PyObject* slicestep = PySlice_Step(slice);
29+
+ if (slicestep != Py_None) {
30+
PyErr_SetString(PyExc_IndexError, "slice with step not supported");
31+
return NULL;
32+
}
133
diff --git a/c/misc_thread_common.h b/c/misc_thread_common.h
234
index 66e2835..b48fd85 100644
335
--- a/c/misc_thread_common.h

graalpython/lib-graalpython/patches/cffi/cffi-1.16.0.patch

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1-
index 7d29634b..bb440851 100644
1+
diff --git a/src/c/_cffi_backend.c b/src/c/_cffi_backend.c
2+
index c5ea2cb..b797540 100644
3+
--- a/src/c/_cffi_backend.c
4+
+++ b/src/c/_cffi_backend.c
5+
@@ -2516,19 +2516,22 @@ _cdata_getslicearg(CDataObject *cd, PySliceObject *slice, Py_ssize_t bounds[])
6+
Py_ssize_t start, stop;
7+
CTypeDescrObject *ct;
8+
9+
- start = PyInt_AsSsize_t(slice->start);
10+
+ PyObject* slicestart = PySlice_Start(slice);
11+
+ start = PyInt_AsSsize_t(slicestart);
12+
if (start == -1 && PyErr_Occurred()) {
13+
- if (slice->start == Py_None)
14+
+ if (slicestart == Py_None)
15+
PyErr_SetString(PyExc_IndexError, "slice start must be specified");
16+
return NULL;
17+
}
18+
- stop = PyInt_AsSsize_t(slice->stop);
19+
+ PyObject* slicestop = PySlice_Stop(slice);
20+
+ stop = PyInt_AsSsize_t(slicestop);
21+
if (stop == -1 && PyErr_Occurred()) {
22+
- if (slice->stop == Py_None)
23+
+ if (slicestop == Py_None)
24+
PyErr_SetString(PyExc_IndexError, "slice stop must be specified");
25+
return NULL;
26+
}
27+
- if (slice->step != Py_None) {
28+
+ PyObject* slicestep = PySlice_Step(slice);
29+
+ if (slicestep != Py_None) {
30+
PyErr_SetString(PyExc_IndexError, "slice with step not supported");
31+
return NULL;
32+
}
33+
diff --git a/src/c/misc_thread_common.h b/src/c/misc_thread_common.h
34+
index ead9c83..a3ca2fe 100644
235
--- a/src/c/misc_thread_common.h
336
+++ b/src/c/misc_thread_common.h
4-
@@ -344,45 +344,7 @@ static PyThreadState *get_current_ts(void)
37+
@@ -342,45 +342,7 @@ static PyThreadState *get_current_ts(void)
538

639
static PyGILState_STATE gil_ensure(void)
740
{

0 commit comments

Comments
 (0)