Index: Lib/test/string_tests.py =================================================================== --- Lib/test/string_tests.py (révision 76700) +++ Lib/test/string_tests.py (copie de travail) @@ -5,6 +5,7 @@ import unittest, string, sys, struct from test import test_support from UserList import UserList +from random import randint class Sequence: def __init__(self, seq='wxyz'): self.seq = seq @@ -185,6 +186,10 @@ self.checkequal(-1, '', 'find', 'xx', 1, 1) self.checkequal(-1, '', 'find', 'xx', sys.maxint, 0) + # issue 7458 + start = randint(sys.maxsize + 1, (sys.maxsize + 1) * 2 - 1) + self.checkequal(-1, 'ab', 'find', 'xxx', start, 0) + # For a variety of combinations, # verify that str.find() matches __contains__ # and that the found substring is really at that location @@ -230,6 +235,10 @@ self.checkraises(TypeError, 'hello', 'rfind') self.checkraises(TypeError, 'hello', 'rfind', 42) + # issue 7458 + start = randint(sys.maxsize + 1, (sys.maxsize + 1) * 2 - 1) + self.checkequal(-1, 'ab', 'rfind', 'xxx', start, 0) + def test_index(self): self.checkequal(0, 'abcdefghiabc', 'index', '') self.checkequal(3, 'abcdefghiabc', 'index', 'def') Index: Objects/stringlib/find.h =================================================================== --- Objects/stringlib/find.h (révision 76700) +++ Objects/stringlib/find.h (copie de travail) @@ -63,6 +63,8 @@ end += str_len; if (end < 0) end = 0; + if (end < start) + return -1; return stringlib_find( str + start, end - start, @@ -85,6 +87,8 @@ end += str_len; if (end < 0) end = 0; + if (end < start) + return -1; return stringlib_rfind(str + start, end - start, sub, sub_len, start); }