comparison mercurial/base85.c @ 16848:19a915d43a68

base85: cast Py_ssize_t values to int (issue3481) If it outputs a nonsense value, no harm done, it was nonsense to start with.
author Adrian Buehlmann <adrian@cadifra.com>
date Mon, 04 Jun 2012 16:59:34 +0200
parents 1b9d54c00d50
children c1aefe57cf4e
comparison
equal deleted inserted replaced
16847:cda5402b1739 16848:19a915d43a68
109 { 109 {
110 c = b85dec[(int)*text++] - 1; 110 c = b85dec[(int)*text++] - 1;
111 if (c < 0) 111 if (c < 0)
112 return PyErr_Format( 112 return PyErr_Format(
113 PyExc_ValueError, 113 PyExc_ValueError,
114 "bad base85 character at position %d", i); 114 "bad base85 character at position %d",
115 (int)i);
115 acc = acc * 85 + c; 116 acc = acc * 85 + c;
116 } 117 }
117 if (i++ < len) 118 if (i++ < len)
118 { 119 {
119 c = b85dec[(int)*text++] - 1; 120 c = b85dec[(int)*text++] - 1;
120 if (c < 0) 121 if (c < 0)
121 return PyErr_Format( 122 return PyErr_Format(
122 PyExc_ValueError, 123 PyExc_ValueError,
123 "bad base85 character at position %d", i); 124 "bad base85 character at position %d",
125 (int)i);
124 /* overflow detection: 0xffffffff == "|NsC0", 126 /* overflow detection: 0xffffffff == "|NsC0",
125 * "|NsC" == 0x03030303 */ 127 * "|NsC" == 0x03030303 */
126 if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c) 128 if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
127 return PyErr_Format( 129 return PyErr_Format(
128 PyExc_ValueError, 130 PyExc_ValueError,
129 "bad base85 sequence at position %d", i); 131 "bad base85 sequence at position %d",
132 (int)i);
130 acc += c; 133 acc += c;
131 } 134 }
132 135
133 cap = olen < 4 ? olen : 4; 136 cap = olen < 4 ? olen : 4;
134 olen -= cap; 137 olen -= cap;