Author: Richard Plangger <[email protected]>
Branch: py3.5
Changeset: r89176:a1d41e7ebbb6
Date: 2016-12-19 09:16 +0100
http://bitbucket.org/pypy/pypy/changeset/a1d41e7ebbb6/

Log:    #2452 check that input of compress/decompress does not overflow 32
        bit

diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -8,6 +8,7 @@
 
 from rpython.rlib import rzlib
 
+UINT_MAX = 2**32-1
 
 @unwrap_spec(string='bufferstr', start='truncatedint_w')
 def crc32(space, string, start = rzlib.CRC32_DEFAULT_START):
@@ -51,6 +52,8 @@
 
     Optional arg level is the compression level, in 1-9.
     """
+    if len(string) > UINT_MAX:
+        raise oefmt(space.w_OverflowError, "Size does not fit in an unsigned 
int")
     try:
         try:
             stream = rzlib.deflateInit(level)
@@ -73,6 +76,8 @@
     Optional arg wbits is the window buffer size.  Optional arg bufsize is
     only for compatibility with CPython and is ignored.
     """
+    if len(string) > UINT_MAX:
+        raise oefmt(space.w_OverflowError, "Size does not fit in an unsigned 
int")
     try:
         try:
             stream = rzlib.inflateInit(wbits)
@@ -147,6 +152,8 @@
 
         Call the flush() method to clear these buffers.
         """
+        if len(data) > UINT_MAX:
+            raise oefmt(space.w_OverflowError, "Size does not fit in an 
unsigned int")
         try:
             self.lock()
             try:
@@ -277,10 +284,12 @@
         unconsumed_tail attribute.
         """
         if max_length == 0:
-            max_length = sys.maxint
+            max_length = UINT_MAX
         elif max_length < 0:
             raise oefmt(space.w_ValueError,
                         "max_length must be greater than zero")
+        elif len(data) > UINT_MAX:
+            raise oefmt(space.w_OverflowError, "Size does not fit in an 
unsigned int")
         try:
             self.lock()
             try:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to