[pypy-commit] pypy py3.6: check for overflow in device_encoding (caused by a bad fileno)

mattip pypy.commits at gmail.com
Tue Feb 4 09:19:53 EST 2020


Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r98661:1c68a492a49e
Date: 2020-02-04 16:12 +0200
http://bitbucket.org/pypy/pypy/changeset/1c68a492a49e/

Log:	check for overflow in device_encoding (caused by a bad fileno)

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -246,9 +246,14 @@
                 e.match(space, space.fromcache(Cache).w_unsupportedoperation)):
             raise
     else:
-        w_encoding = device_encoding(space, space.int_w(w_fileno))
-        if space.isinstance_w(w_encoding, space.w_unicode):
-            return w_encoding
+        try:
+            w_encoding = device_encoding(space, space.int_w(w_fileno))
+        except OverflowError:
+            raise oefmt(space.w_OverflowError,
+                        "Python int too large to convert to C int")
+        else:
+            if space.isinstance_w(w_encoding, space.w_unicode):
+                return w_encoding
 
     # On legacy systems or darwin, try app-level 
     # _bootlocale.getprefferedencoding(False)


More information about the pypy-commit mailing list