@@ -271,6 +271,10 @@ def __check_input_type(self, input):
271
271
if self .__binary and isinstance (input , str ):
272
272
raise TypeError ("cannot use a bytes pattern on a string-like object" )
273
273
274
+ @staticmethod
275
+ def __check_pos (pos ):
276
+ if pos > maxsize ():
277
+ raise OverflowError ('Python int too large to convert to Java int' )
274
278
275
279
def __tregex_compile (self , pattern , flags = None ):
276
280
if flags is None :
@@ -313,7 +317,7 @@ def _search(self, pattern, string, pos, endpos, sticky=False):
313
317
input_str = string
314
318
if endpos == - 1 or endpos >= len (string ):
315
319
endpos = len (string )
316
- result = tregex_call_exec (pattern .exec , input_str , min (pos , len ( string ) + 1 ))
320
+ result = tregex_call_exec (pattern .exec , input_str , min (pos , endpos ))
317
321
else :
318
322
input_str = string [:endpos ]
319
323
result = tregex_call_exec (pattern .exec , input_str , min (pos , endpos % len (string ) + 1 ))
@@ -323,14 +327,17 @@ def _search(self, pattern, string, pos, endpos, sticky=False):
323
327
return None
324
328
325
329
def search (self , string , pos = 0 , endpos = None ):
330
+ self .__check_pos (pos )
326
331
self .__check_input_type (string )
327
332
return self ._search (self .pattern , string , pos , default (endpos , - 1 ))
328
333
329
334
def match (self , string , pos = 0 , endpos = None ):
335
+ self .__check_pos (pos )
330
336
self .__check_input_type (string )
331
337
return self ._search (self .pattern , string , pos , default (endpos , - 1 ), sticky = True )
332
338
333
339
def fullmatch (self , string , pos = 0 , endpos = None ):
340
+ self .__check_pos (pos )
334
341
self .__check_input_type (string )
335
342
return self ._search (_append_end_assert (self .pattern ), string , pos , default (endpos , - 1 ), sticky = True )
336
343
0 commit comments