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