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:
Serhiy Storchaka 2013-01-19 12:41:45 +02:00
commit 9101e23ff6
19 changed files with 151 additions and 25 deletions

View file

@ -32,6 +32,7 @@ import time
import unittest
import warnings
import weakref
import _testcapi
from collections import deque, UserList
from itertools import cycle, count
from test import support
@ -1962,6 +1963,14 @@ class TextIOWrapperTest(unittest.TestCase):
os.environ.clear()
os.environ.update(old_environ)
# Issue 15989
def test_device_encoding(self):
b = self.BytesIO()
b.fileno = lambda: _testcapi.INT_MAX + 1
self.assertRaises(OverflowError, self.TextIOWrapper, b)
b.fileno = lambda: _testcapi.UINT_MAX + 1
self.assertRaises(OverflowError, self.TextIOWrapper, b)
def test_encoding(self):
# Check the encoding attribute is always set, and valid
b = self.BytesIO()