Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 065e2ae

Browse filesBrowse files
[3.11] gh-104265 Disallow instantiation of _csv.Reader and _csv.Writer (GH-104266) (#104278)
gh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` (GH-104266) (cherry picked from commit 06c2a48) Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
1 parent 681d502 commit 065e2ae
Copy full SHA for 065e2ae

File tree

3 files changed

+14
-3
lines changed
Filter options

3 files changed

+14
-3
lines changed

‎Lib/test/test_csv.py

Copy file name to clipboardExpand all lines: Lib/test/test_csv.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import gc
1111
import pickle
1212
from test import support
13-
from test.support import warnings_helper
13+
from test.support import warnings_helper, import_helper, check_disallow_instantiation
1414
from itertools import permutations
1515
from textwrap import dedent
1616
from collections import OrderedDict
@@ -1390,5 +1390,12 @@ def test_subclassable(self):
13901390
# issue 44089
13911391
class Foo(csv.Error): ...
13921392

1393+
@support.cpython_only
1394+
def test_disallow_instantiation(self):
1395+
_csv = import_helper.import_module("_csv")
1396+
for tp in _csv.Reader, _csv.Writer:
1397+
with self.subTest(tp=tp):
1398+
check_disallow_instantiation(self, tp)
1399+
13931400
if __name__ == '__main__':
13941401
unittest.main()
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Prevent possible crash by disallowing instantiation of the
2+
:class:`!_csv.Reader` and :class:`!_csv.Writer` types.
3+
The regression was introduced in 3.10.0a4 with PR 23224 (:issue:`14935`).
4+
Patch by Radislav Chugunov.

‎Modules/_csv.c

Copy file name to clipboardExpand all lines: Modules/_csv.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ PyType_Spec Reader_Type_spec = {
10001000
.name = "_csv.reader",
10011001
.basicsize = sizeof(ReaderObj),
10021002
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1003-
Py_TPFLAGS_IMMUTABLETYPE),
1003+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
10041004
.slots = Reader_Type_slots
10051005
};
10061006

@@ -1425,7 +1425,7 @@ PyType_Spec Writer_Type_spec = {
14251425
.name = "_csv.writer",
14261426
.basicsize = sizeof(WriterObj),
14271427
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1428-
Py_TPFLAGS_IMMUTABLETYPE),
1428+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
14291429
.slots = Writer_Type_slots,
14301430
};
14311431

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.