patches/Python26-22-audio.diff
author rohinis
Tue, 29 Nov 2011 17:32:55 +0000
branchs11express-2010-11
changeset 22234 c23e64da3e06
permissions -rw-r--r--
2011-11-29 Rohini S <[email protected]> * patches/Python26-22-audio.diff: Fixes CVE-2010-1634 * specs/SUNWPython26.spec: Fixes CR 7085446
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22234
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     1
--- a/Modules/audioop.c	2011-09-25 05:24:35.789815000 +0100
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     2
+++ b/Modules/audioop.c	2011-09-25 06:55:35.782359000 +0100
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     3
@@ -829,7 +829,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     4
 audioop_tostereo(PyObject *self, PyObject *args)
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     5
 {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     6
         signed char *cp, *ncp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     7
-        int len, new_len, size, val1, val2, val = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     8
+        int len, size, val1, val2, val = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
     9
         double fac1, fac2, fval, maxval;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    10
         PyObject *rv;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    11
         int i;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    12
@@ -846,14 +846,13 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    13
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    14
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    15
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    16
-        new_len = len*2;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    17
-        if (new_len < 0) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    18
+        if (len > INT_MAX/2) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    19
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    20
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    21
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    22
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    23
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    24
-        rv = PyString_FromStringAndSize(NULL, new_len);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    25
+        rv = PyString_FromStringAndSize(NULL, len*2);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    26
         if ( rv == 0 )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    27
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    28
         ncp = (signed char *)PyString_AsString(rv);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    29
@@ -1016,7 +1015,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    30
 {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    31
         signed char *cp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    32
         unsigned char *ncp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    33
-        int len, new_len, size, size2, val = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    34
+        int len, size, size2, val = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    35
         PyObject *rv;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    36
         int i, j;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    37
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    38
@@ -1030,13 +1029,12 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    39
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    40
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    41
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    42
-        new_len = (len/size)*size2;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    43
-        if (new_len < 0) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    44
+        if (len/size > INT_MAX/size2) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    45
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    46
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    47
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    48
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    49
-        rv = PyString_FromStringAndSize(NULL, new_len);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    50
+        rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    51
         if ( rv == 0 )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    52
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    53
         ncp = (unsigned char *)PyString_AsString(rv);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    54
@@ -1072,7 +1070,6 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    55
         int chan, d, *prev_i, *cur_i, cur_o;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    56
         PyObject *state, *samps, *str, *rv = NULL;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    57
         int bytes_per_frame;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    58
-        size_t alloc_size;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    59
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    60
         weightA = 1;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    61
         weightB = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    62
@@ -1115,14 +1112,13 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    63
         inrate /= d;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    64
         outrate /= d;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    65
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    66
-        alloc_size = sizeof(int) * (unsigned)nchannels;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    67
-        if (alloc_size < nchannels) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    68
+	if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    69
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    70
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    71
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    72
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    73
-        prev_i = (int *) malloc(alloc_size);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    74
-        cur_i = (int *) malloc(alloc_size);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    75
+        prev_i = (int *) malloc(nchannels * sizeof(int));
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    76
+        cur_i = (int *) malloc(nchannels * sizeof(int));
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    77
         if (prev_i == NULL || cur_i == NULL) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    78
                 (void) PyErr_NoMemory();
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    79
                 goto exit;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    80
@@ -1160,24 +1156,11 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    81
                    requires bytes_per_frame bytes.  Computing this
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    82
                    without spurious overflow is the challenge; we can
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    83
                    settle for a reasonable upper bound, though. */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    84
-                int ceiling;   /* the number of output frames */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    85
-                int nbytes;    /* the number of output bytes needed */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    86
-                int q = len / inrate;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    87
-                /* Now len = q * inrate + r exactly (with r = len % inrate),
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    88
-                   and this is less than q * inrate + inrate = (q+1)*inrate.
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    89
-                   So a reasonable upper bound on len*outrate/inrate is
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    90
-                   ((q+1)*inrate)*outrate/inrate =
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    91
-                   (q+1)*outrate.
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    92
-                */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    93
-                ceiling = (q+1) * outrate;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    94
-                nbytes = ceiling * bytes_per_frame;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    95
-                /* See whether anything overflowed; if not, get the space. */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    96
-                if (q+1 < 0 ||
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    97
-                    ceiling / outrate != q+1 ||
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    98
-                    nbytes / bytes_per_frame != ceiling)
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
    99
+                int q = len > 0 ? 1 + (len - 1) / inrate : 0; 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   100
+		if (outrate > INT_MAX / q / bytes_per_frame)
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   101
                         str = NULL;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   102
                 else
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   103
-                        str = PyString_FromStringAndSize(NULL, nbytes);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   104
+                        str = PyString_FromStringAndSize(NULL, q * outrate * bytes_per_frame);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   105
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   106
                 if (str == NULL) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   107
                         PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   108
@@ -1296,7 +1279,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   109
         unsigned char *cp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   110
         unsigned char cval;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   111
         signed char *ncp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   112
-        int len, new_len, size, val;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   113
+        int len, size, val;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   114
         PyObject *rv;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   115
         int i;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   116
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   117
@@ -1309,18 +1292,17 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   118
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   119
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   120
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   121
-        new_len = len*size;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   122
-        if (new_len < 0) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   123
+        if (len > INT_MAX/size) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   124
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   125
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   126
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   127
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   128
-        rv = PyString_FromStringAndSize(NULL, new_len);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   129
+        rv = PyString_FromStringAndSize(NULL, len*size);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   130
         if ( rv == 0 )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   131
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   132
         ncp = (signed char *)PyString_AsString(rv);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   133
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   134
-        for ( i=0; i < new_len; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   135
+        for ( i=0; i < len*size; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   136
                 cval = *cp++;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   137
                 val = st_ulaw2linear16(cval);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   138
         
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   139
@@ -1370,7 +1352,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   140
         unsigned char *cp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   141
         unsigned char cval;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   142
         signed char *ncp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   143
-        int len, new_len, size, val;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   144
+        int len, size, val;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   145
         PyObject *rv;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   146
         int i;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   147
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   148
@@ -1383,18 +1365,17 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   149
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   150
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   151
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   152
-        new_len = len*size;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   153
-        if (new_len < 0) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   154
+        if (len > INT_MAX/size) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   155
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   156
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   157
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   158
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   159
-        rv = PyString_FromStringAndSize(NULL, new_len);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   160
+        rv = PyString_FromStringAndSize(NULL, len*size);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   161
         if ( rv == 0 )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   162
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   163
         ncp = (signed char *)PyString_AsString(rv);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   164
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   165
-        for ( i=0; i < new_len; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   166
+        for ( i=0; i < len*size; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   167
                 cval = *cp++;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   168
                 val = st_alaw2linear16(cval);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   169
         
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   170
@@ -1519,7 +1500,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   171
 {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   172
         signed char *cp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   173
         signed char *ncp;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   174
-        int len, new_len, size, valpred, step, delta, index, sign, vpdiff;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   175
+        int len, size, valpred, step, delta, index, sign, vpdiff;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   176
         PyObject *rv, *str, *state;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   177
         int i, inputbuffer = 0, bufferstep;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   178
 
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   179
@@ -1541,13 +1522,12 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   180
         } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   181
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   182
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   183
-        new_len = len*size*2;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   184
-        if (new_len < 0) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   185
+        if (len > (INT_MAX/2)/size) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   186
                 PyErr_SetString(PyExc_MemoryError,
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   187
                                 "not enough memory for output buffer");
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   188
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   189
         }
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   190
-        str = PyString_FromStringAndSize(NULL, new_len);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   191
+        str = PyString_FromStringAndSize(NULL, len*size*2);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   192
         if ( str == 0 )
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   193
                 return 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   194
         ncp = (signed char *)PyString_AsString(str);
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   195
@@ -1555,7 +1535,7 @@
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   196
         step = stepsizeTable[index];
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   197
         bufferstep = 0;
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   198
     
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   199
-        for ( i=0; i < new_len; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   200
+        for ( i=0; i < len*size*2; i += size ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   201
                 /* Step 1 - get the delta value and compute next index */
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   202
                 if ( bufferstep ) {
c23e64da3e06 2011-11-29 Rohini S <[email protected]>
rohinis
parents:
diff changeset
   203
                         delta = inputbuffer & 0xf;