mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-31577: Fix a crash in os.utime() in case of a bad ns argument. (GH-3752)
This commit is contained in:
parent
e502451781
commit
0bd1a2dcfd
3 changed files with 24 additions and 0 deletions
|
@ -635,6 +635,22 @@ class UtimeTests(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
os.utime(self.fname, (5, 5), ns=(5, 5))
|
||||
|
||||
@support.cpython_only
|
||||
def test_issue31577(self):
|
||||
# The interpreter shouldn't crash in case utime() received a bad
|
||||
# ns argument.
|
||||
def get_bad_int(divmod_ret_val):
|
||||
class BadInt:
|
||||
def __divmod__(*args):
|
||||
return divmod_ret_val
|
||||
return BadInt()
|
||||
with self.assertRaises(TypeError):
|
||||
os.utime(self.fname, ns=(get_bad_int(42), 1))
|
||||
with self.assertRaises(TypeError):
|
||||
os.utime(self.fname, ns=(get_bad_int(()), 1))
|
||||
with self.assertRaises(TypeError):
|
||||
os.utime(self.fname, ns=(get_bad_int((1, 2, 3)), 1))
|
||||
|
||||
|
||||
from test import mapping_tests
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue