[3.13] gh-127196: Fix crash in _interpreters, when shared had invalid encodings (GH-127220) (#128689)

gh-127196: Fix crash in `_interpreters`, when `shared` had invalid encodings (GH-127220)
(cherry picked from commit 087bb48aca)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2025-01-09 21:10:08 +01:00 committed by GitHub
parent c57ef49337
commit 0d2b9abd18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -557,7 +557,7 @@ class CommonTests(TestBase):
self.id = _interpreters.create()
def test_signatures(self):
# for method in ['exec', 'run_string', 'run_func']:
# See https://github.com/python/cpython/issues/126654
msg = "expected 'shared' to be a dict"
with self.assertRaisesRegex(TypeError, msg):
_interpreters.exec(self.id, 'a', 1)
@ -568,6 +568,17 @@ class CommonTests(TestBase):
with self.assertRaisesRegex(TypeError, msg):
_interpreters.run_func(self.id, lambda: None, shared=1)
def test_invalid_shared_encoding(self):
# See https://github.com/python/cpython/issues/127196
bad_shared = {"\uD82A": 0}
msg = 'surrogates not allowed'
with self.assertRaisesRegex(UnicodeEncodeError, msg):
_interpreters.exec(self.id, 'a', shared=bad_shared)
with self.assertRaisesRegex(UnicodeEncodeError, msg):
_interpreters.run_string(self.id, 'a', shared=bad_shared)
with self.assertRaisesRegex(UnicodeEncodeError, msg):
_interpreters.run_func(self.id, lambda: None, shared=bad_shared)
class RunStringTests(TestBase):