cairomm, glibmm, gsl, gtkmm, libsigc++, pangomm packages.
[fedora-mingw.git] / python / python-2.5-CVE-2008-2316.patch
1 Index: Lib/test/test_hashlib.py
2 ===================================================================
3 --- Lib/test/test_hashlib.py    (revision 64642)
4 +++ Lib/test/test_hashlib.py    (working copy)
5 @@ -9,8 +9,8 @@
6  import hashlib
7  import unittest
8  from test import test_support
9 +from test.test_support import _4G, precisionbigmemtest
10  
11 -
12  def hexstr(s):
13      import string
14      h = string.hexdigits
15 @@ -55,7 +55,6 @@
16              m2.update(aas + bees + cees)
17              self.assertEqual(m1.digest(), m2.digest())
18  
19 -
20      def check(self, name, data, digest):
21          # test the direct constructors
22          computed = getattr(hashlib, name)(data).hexdigest()
23 @@ -74,8 +73,23 @@
24      def test_case_md5_2(self):
25          self.check('md5', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
26                     'd174ab98d277d9f5a5611c2c9f419d9f')
27 +    
28 +    @precisionbigmemtest(size=_4G + 5, memuse=1)
29 +    def test_case_md5_huge(self, size):
30 +        if size == _4G + 5:
31 +            try:
32 +                self.check('md5', 'A'*size, 'c9af2dff37468ce5dfee8f2cfc0a9c6d')
33 +            except OverflowError:
34 +                pass # 32-bit arch
35 +    
36 +    @precisionbigmemtest(size=_4G - 1, memuse=1)
37 +    def test_case_md5_uintmax(self, size):
38 +        if size == _4G - 1:
39 +            try:
40 +                self.check('md5', 'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
41 +            except OverflowError:
42 +                pass # 32-bit arch
43  
44 -
45      # use the three examples from Federal Information Processing Standards
46      # Publication 180-1, Secure Hash Standard,  1995 April 17
47      # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
48 Index: Modules/_hashopenssl.c
49 ===================================================================
50 --- Modules/_hashopenssl.c      (revision 64642)
51 +++ Modules/_hashopenssl.c      (working copy)
52 @@ -19,7 +19,9 @@
53  /* EVP is the preferred interface to hashing in OpenSSL */
54  #include <openssl/evp.h>
55  
56 +#define MUNCH_SIZE INT_MAX
57  
58 +
59  #ifndef HASH_OBJ_CONSTRUCTOR
60  #define HASH_OBJ_CONSTRUCTOR 0
61  #endif
62 @@ -164,9 +166,18 @@
63      if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
64          return NULL;
65  
66 +    if (len > 0 && len <= MUNCH_SIZE) {
67      EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
68                                                        unsigned int));
69 -
70 +    } else {
71 +        Py_ssize_t offset = 0;
72 +        while (len) {
73 +            unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
74 +            EVP_DigestUpdate(&self->ctx, cp + offset, process);
75 +            len -= process;
76 +            offset += process;
77 +        }
78 +    }
79      Py_INCREF(Py_None);
80      return Py_None;
81  }
82 @@ -255,10 +266,21 @@
83      self->name = name_obj;
84      Py_INCREF(self->name);
85  
86 -    if (cp && len)
87 +    if (cp && len) {
88 +        if (len > 0 && len <= MUNCH_SIZE) {
89          EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
90                                                            unsigned int));
91 -
92 +        } else {
93 +            Py_ssize_t offset = 0;
94 +            while (len) {
95 +                unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
96 +                EVP_DigestUpdate(&self->ctx, cp + offset, process);
97 +                len -= process;
98 +                offset += process;
99 +            }
100 +        }
101 +    }
102 +    
103      return 0;
104  }
105  #endif
106 @@ -328,7 +350,7 @@
107  static PyObject *
108  EVPnew(PyObject *name_obj,
109         const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
110 -       const unsigned char *cp, unsigned int len)
111 +       const unsigned char *cp, Py_ssize_t len)
112  {
113      EVPobject *self;
114  
115 @@ -346,8 +368,20 @@
116          EVP_DigestInit(&self->ctx, digest);
117      }
118  
119 -    if (cp && len)
120 -        EVP_DigestUpdate(&self->ctx, cp, len);
121 +    if (cp && len) {
122 +        if (len > 0 && len <= MUNCH_SIZE) {
123 +            EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
124 +                                                              unsigned int));
125 +        } else {
126 +            Py_ssize_t offset = 0;
127 +            while (len) {
128 +                unsigned int process = len > MUNCH_SIZE ? MUNCH_SIZE : len;
129 +                EVP_DigestUpdate(&self->ctx, cp + offset, process);
130 +                len -= process;
131 +                offset += process;
132 +            }
133 +        }
134 +    }
135  
136      return (PyObject *)self;
137  }
138 @@ -384,8 +418,7 @@
139  
140      digest = EVP_get_digestbyname(name);
141  
142 -    return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t,
143 -                                                               unsigned int));
144 +    return EVPnew(name_obj, digest, NULL, cp, len);
145  }
146  
147  /*
148 @@ -410,7 +443,7 @@
149                  CONST_ ## NAME ## _name_obj, \
150                  NULL, \
151                  CONST_new_ ## NAME ## _ctx_p, \
152 -                cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \
153 +                cp, len); \
154      }
155  
156  /* a PyMethodDef structure for the constructor */