diff --git a/mercurial/base85.c b/mercurial/base85.c
--- a/mercurial/base85.c
+++ b/mercurial/base85.c
@@ -109,7 +109,7 @@ b85decode(PyObject *self, PyObject *args
 			if (c < 0)
 				return PyErr_Format(
 					PyExc_ValueError,
-					"Bad base85 character at position %d", i);
+					"bad base85 character at position %d", i);
 			acc = acc * 85 + c;
 		}
 		if (i++ < len)
@@ -118,13 +118,13 @@ b85decode(PyObject *self, PyObject *args
 			if (c < 0)
 				return PyErr_Format(
 					PyExc_ValueError,
-					"Bad base85 character at position %d", i);
+					"bad base85 character at position %d", i);
 			/* overflow detection: 0xffffffff == "|NsC0",
 			 * "|NsC" == 0x03030303 */
 			if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
 				return PyErr_Format(
 					PyExc_ValueError,
-					"Bad base85 sequence at position %d", i);
+					"bad base85 sequence at position %d", i);
 			acc += c;
 		}
 
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1051,7 +1051,11 @@ class binhunk(object):
                 l = ord(l) - ord('A') + 1
             else:
                 l = ord(l) - ord('a') + 27
-            dec.append(base85.b85decode(line[1:-1])[:l])
+            try:
+                dec.append(base85.b85decode(line[1:-1])[:l])
+            except ValueError, e:
+                raise PatchError(_('could not decode binary patch: %s')
+                                 % str(e))
             line = lr.readline()
             self.hunk.append(line)
         text = zlib.decompress(''.join(dec))
diff --git a/tests/test-import-git.t b/tests/test-import-git.t
--- a/tests/test-import-git.t
+++ b/tests/test-import-git.t
@@ -362,6 +362,25 @@ Move text file and patch as binary
   A binary2
     text2
   R text2
+
+Invalid base85 content
+  $ hg rollback
+  repository tip rolled back to revision 15 (undo import)
+  working directory now based on revision 15
+  $ hg revert -aq
+  $ hg import -d "1000000 0" -m invalid-binary - <<"EOF"
+  > diff --git a/text2 b/binary2
+  > rename from text2
+  > rename to binary2
+  > index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757
+  > GIT binary patch
+  > literal 5
+  > Mc$`b*O.$Pw00T?_*Z=?k
+  > 
+  > EOF
+  applying patch from stdin
+  abort: could not decode binary patch: bad base85 character at position 6
+  [255]
   $ cd ..
 
 Consecutive import with renames (issue2459)