[3.11] gh-98744: Prevent column-level decoding crashes on traceback module (#98850)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
Batuhan Taskaya 2022-10-29 17:12:15 +03:00 committed by GitHub
parent 12957d7cbd
commit 751da28feb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 14 deletions

View file

@ -778,6 +778,56 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
]
self.assertEqual(actual, expected)
def test_wide_characters_unicode_with_problematic_byte_offset(self):
def f():
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 1}, in f",
f" ",
]
self.assertEqual(actual, expected)
def test_byte_offset_with_wide_characters_middle(self):
def f():
= 1
raise ValueError()
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 2}, in f",
f" raise ValueError()",
]
self.assertEqual(actual, expected)
def test_byte_offset_multiline(self):
def f():
= 1
= 0
print(1, (
))
actual = self.get_exception(f)
expected = [
f"Traceback (most recent call last):",
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
f" callable()",
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 4}, in f",
f" print(1, (",
f" ^^^^",
]
self.assertEqual(actual, expected)
@cpython_only
@requires_debug_ranges()
class CPythonTracebackErrorCaretTests(TracebackErrorLocationCaretTests):