gh-98744: Prevent column-level decoding crashes on traceback module (#98824)

This commit is contained in:
Batuhan Taskaya 2022-10-29 15:28:20 +03:00 committed by GitHub
parent 7ea10567af
commit c0f2a5ef91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 14 deletions

View file

@ -804,6 +804,56 @@ class TracebackErrorLocationCaretTestBase:
]
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)
@requires_debug_ranges()
class PurePythonTracebackErrorCaretTests(