##// END OF EJS Templates
patch: display a nice error for invalid base85 data...
Patrick Mezard -
r16522:a8065323 stable
parent child Browse files
Show More
@@ -109,7 +109,7 b' b85decode(PyObject *self, PyObject *args'
109 if (c < 0)
109 if (c < 0)
110 return PyErr_Format(
110 return PyErr_Format(
111 PyExc_ValueError,
111 PyExc_ValueError,
112 "Bad base85 character at position %d", i);
112 "bad base85 character at position %d", i);
113 acc = acc * 85 + c;
113 acc = acc * 85 + c;
114 }
114 }
115 if (i++ < len)
115 if (i++ < len)
@@ -118,13 +118,13 b' b85decode(PyObject *self, PyObject *args'
118 if (c < 0)
118 if (c < 0)
119 return PyErr_Format(
119 return PyErr_Format(
120 PyExc_ValueError,
120 PyExc_ValueError,
121 "Bad base85 character at position %d", i);
121 "bad base85 character at position %d", i);
122 /* overflow detection: 0xffffffff == "|NsC0",
122 /* overflow detection: 0xffffffff == "|NsC0",
123 * "|NsC" == 0x03030303 */
123 * "|NsC" == 0x03030303 */
124 if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
124 if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
125 return PyErr_Format(
125 return PyErr_Format(
126 PyExc_ValueError,
126 PyExc_ValueError,
127 "Bad base85 sequence at position %d", i);
127 "bad base85 sequence at position %d", i);
128 acc += c;
128 acc += c;
129 }
129 }
130
130
@@ -1051,7 +1051,11 b' class binhunk(object):'
1051 l = ord(l) - ord('A') + 1
1051 l = ord(l) - ord('A') + 1
1052 else:
1052 else:
1053 l = ord(l) - ord('a') + 27
1053 l = ord(l) - ord('a') + 27
1054 dec.append(base85.b85decode(line[1:-1])[:l])
1054 try:
1055 dec.append(base85.b85decode(line[1:-1])[:l])
1056 except ValueError, e:
1057 raise PatchError(_('could not decode binary patch: %s')
1058 % str(e))
1055 line = lr.readline()
1059 line = lr.readline()
1056 self.hunk.append(line)
1060 self.hunk.append(line)
1057 text = zlib.decompress(''.join(dec))
1061 text = zlib.decompress(''.join(dec))
@@ -362,6 +362,25 b' Move text file and patch as binary'
362 A binary2
362 A binary2
363 text2
363 text2
364 R text2
364 R text2
365
366 Invalid base85 content
367 $ hg rollback
368 repository tip rolled back to revision 15 (undo import)
369 working directory now based on revision 15
370 $ hg revert -aq
371 $ hg import -d "1000000 0" -m invalid-binary - <<"EOF"
372 > diff --git a/text2 b/binary2
373 > rename from text2
374 > rename to binary2
375 > index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757
376 > GIT binary patch
377 > literal 5
378 > Mc$`b*O.$Pw00T?_*Z=?k
379 >
380 > EOF
381 applying patch from stdin
382 abort: could not decode binary patch: bad base85 character at position 6
383 [255]
365 $ cd ..
384 $ cd ..
366
385
367 Consecutive import with renames (issue2459)
386 Consecutive import with renames (issue2459)
General Comments 0
You need to be logged in to leave comments. Login now