Show More
@@ -77,7 +77,7 b' static PyObject *b85encode(PyObject *sel' | |||
|
77 | 77 | |
|
78 | 78 | static PyObject *b85decode(PyObject *self, PyObject *args) |
|
79 | 79 | { |
|
80 | PyObject *out; | |
|
80 | PyObject *out = NULL; | |
|
81 | 81 | const char *text; |
|
82 | 82 | char *dst; |
|
83 | 83 | Py_ssize_t len, i, j, olen, cap; |
@@ -104,27 +104,33 b' static PyObject *b85decode(PyObject *sel' | |||
|
104 | 104 | cap = 4; |
|
105 | 105 | for (j = 0; j < cap; i++, j++) { |
|
106 | 106 | c = b85dec[(int)*text++] - 1; |
|
107 | if (c < 0) | |
|
108 |
|
|
|
107 | if (c < 0) { | |
|
108 | PyErr_Format( | |
|
109 | 109 | PyExc_ValueError, |
|
110 | 110 | "bad base85 character at position %d", |
|
111 | 111 | (int)i); |
|
112 | goto bail; | |
|
113 | } | |
|
112 | 114 | acc = acc * 85 + c; |
|
113 | 115 | } |
|
114 | 116 | if (i++ < len) { |
|
115 | 117 | c = b85dec[(int)*text++] - 1; |
|
116 | if (c < 0) | |
|
117 |
|
|
|
118 | if (c < 0) { | |
|
119 | PyErr_Format( | |
|
118 | 120 | PyExc_ValueError, |
|
119 | 121 | "bad base85 character at position %d", |
|
120 | 122 | (int)i); |
|
123 | goto bail; | |
|
124 | } | |
|
121 | 125 | /* overflow detection: 0xffffffff == "|NsC0", |
|
122 | 126 | * "|NsC" == 0x03030303 */ |
|
123 | if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c) | |
|
124 |
|
|
|
127 | if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c) { | |
|
128 | PyErr_Format( | |
|
125 | 129 | PyExc_ValueError, |
|
126 | 130 | "bad base85 sequence at position %d", |
|
127 | 131 | (int)i); |
|
132 | goto bail; | |
|
133 | } | |
|
128 | 134 | acc += c; |
|
129 | 135 | } |
|
130 | 136 | |
@@ -141,6 +147,9 b' static PyObject *b85decode(PyObject *sel' | |||
|
141 | 147 | } |
|
142 | 148 | |
|
143 | 149 | return out; |
|
150 | bail: | |
|
151 | Py_XDECREF(out); | |
|
152 | return NULL; | |
|
144 | 153 | } |
|
145 | 154 | |
|
146 | 155 | static char base85_doc[] = "Base85 Data Encoding"; |
General Comments 0
You need to be logged in to leave comments.
Login now