mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks. This is a backport of changesets 13e2e44db99d and 525407d89277.
This commit is contained in:
		
							parent
							
								
									ff12fae80e
								
							
						
					
					
						commit
						441d30fac7
					
				
					 16 changed files with 129 additions and 20 deletions
				
			
		|  | @ -5,6 +5,7 @@ | |||
| import unittest, string, sys, struct | ||||
| from test import support | ||||
| from collections import UserList | ||||
| import _testcapi | ||||
| 
 | ||||
| class Sequence: | ||||
|     def __init__(self, seq='wxyz'): self.seq = seq | ||||
|  | @ -1142,6 +1143,16 @@ def test_formatting(self): | |||
|         self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) | ||||
|         self.checkraises(ValueError, '%10', '__mod__', (42,)) | ||||
| 
 | ||||
|         self.checkraises(OverflowError, '%*s', '__mod__', | ||||
|                          (_testcapi.PY_SSIZE_T_MAX + 1, '')) | ||||
|         self.checkraises(OverflowError, '%.*f', '__mod__', | ||||
|                          (_testcapi.INT_MAX + 1, 1. / 7)) | ||||
|         # Issue 15989 | ||||
|         self.checkraises(OverflowError, '%*s', '__mod__', | ||||
|                          (1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1), '')) | ||||
|         self.checkraises(OverflowError, '%.*f', '__mod__', | ||||
|                          (_testcapi.UINT_MAX + 1, 1. / 7)) | ||||
| 
 | ||||
|         class X(object): pass | ||||
|         self.checkraises(TypeError, 'abc', '__mod__', X()) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka