]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport fixes from 2.32 and 2.29:
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 1 Nov 2001 11:30:06 +0000 (11:30 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 1 Nov 2001 11:30:06 +0000 (11:30 +0000)
  Change the limit on the input size for b2a_base64 to what will fit in
  memory, rather than the standard's 57.
  This fixes SF bug #473009.

  This closes bug #430849 (internal error produced by binascii.a2b_base64)

Modules/binascii.c

index 85edd044f6e8c51de9d7cb8808eadb11bc71bd16..efe6608c365ead6782867f7135116fcc090c1e80 100644 (file)
@@ -126,7 +126,9 @@ static char table_a2b_base64[] = {
 };
 
 #define BASE64_PAD '='
-#define BASE64_MAXBIN 57       /* Max binary chunk size (76 char line) */
+
+/* Max binary chunk size; limited only by available memory */
+#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyStringObject))
 
 static unsigned char table_b2a_base64[] =
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -335,6 +337,10 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
        if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) )
                return NULL;
 
+       if ( ascii_len == 0) {
+               PyErr_SetString(Error, "Cannot decode empty input");
+               return NULL;
+       }
        bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
 
        /* Allocate the buffer */