summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-07-13 13:58:03 (GMT)
committerGitHub <noreply@github.com>2025-07-13 13:58:03 (GMT)
commit348e22cf060695fbd57f099b94f0f9067bb49fca (patch)
tree5922d8aed5cc0fd74bb75ef1fa2673dc10ebfecf /Lib/test/string_tests.py
parented1e0cdc581d328177992e45c74d497c7da22ce2 (diff)
downloadcpython-348e22cf060695fbd57f099b94f0f9067bb49fca.zip
cpython-348e22cf060695fbd57f099b94f0f9067bb49fca.tar.gz
cpython-348e22cf060695fbd57f099b94f0f9067bb49fca.tar.bz2
[3.14] gh-127971: fix off-by-one read beyond the end of a string during search (GH-132574) (#136628)
gh-127971: fix off-by-one read beyond the end of a string during search (GH-132574) (cherry picked from commit 85ec3b3b503ffd5b7e45f8b3fa2cec0c10e4bef0) Co-authored-by: Duane Griffin <duaneg@dghda.com>
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 4b82d51..1814a55 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -767,6 +767,15 @@ class BaseTest:
self.checkraises(TypeError, 'hello', 'replace', 42, 'h')
self.checkraises(TypeError, 'hello', 'replace', 'h', 42)
+ def test_replacement_on_buffer_boundary(self):
+ # gh-127971: Check we don't read past the end of the buffer when a
+ # potential match misses on the last character.
+ any_3_nonblank_codepoints = '!!!'
+ seven_codepoints = any_3_nonblank_codepoints + ' ' + any_3_nonblank_codepoints
+ a = (' ' * 243) + seven_codepoints + (' ' * 7)
+ b = ' ' * 6 + chr(256)
+ a.replace(seven_codepoints, b)
+
def test_replace_uses_two_way_maxcount(self):
# Test that maxcount works in _two_way_count in fastsearch.h
A, B = "A"*1000, "B"*1000