summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCharlie Zhao <zhaoyu_hit@qq.com>2023-07-31 12:34:16 (GMT)
committerGitHub <noreply@github.com>2023-07-31 12:34:16 (GMT)
commit99518bbbf47a198f8c51e82e7357ac7efdafdcd8 (patch)
treeac26477228907ac6240a5c6c432985d9229e5d49 /Lib/test
parent8f080a290bd45f4664d3a457256310cc02883d7d (diff)
downloadcpython-99518bbbf47a198f8c51e82e7357ac7efdafdcd8.zip
cpython-99518bbbf47a198f8c51e82e7357ac7efdafdcd8.tar.gz
cpython-99518bbbf47a198f8c51e82e7357ac7efdafdcd8.tar.bz2
[3.12] gh-106263: Fix segfault in `signaldict_repr` in `_decimal` module (#… (#107491)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> (cherry picked from commit 3979150a0d406707f6d253d7c15fb32c1e005a77)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_decimal.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 749496e..d0ba348 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -5682,6 +5682,36 @@ class CWhitebox(unittest.TestCase):
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
+ def test_c_signaldict_segfault(self):
+ # See gh-106263 for details.
+ SignalDict = type(C.Context().flags)
+ sd = SignalDict()
+ err_msg = "invalid signal dict"
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ len(sd)
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ iter(sd)
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ repr(sd)
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ sd[C.InvalidOperation] = True
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ sd[C.InvalidOperation]
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ sd == C.Context().flags
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ C.Context().flags == sd
+
+ with self.assertRaisesRegex(ValueError, err_msg):
+ sd.copy()
+
@requires_docstrings
@requires_cdecimal
class SignatureTest(unittest.TestCase):