--- a/mercurial/changegroup.py Tue Feb 22 03:03:39 2011 +0100
+++ b/mercurial/changegroup.py Tue Feb 22 03:10:37 2011 +0100
@@ -23,6 +23,8 @@
d = readexactly(stream, 4)
l = struct.unpack(">l", d)[0]
if l <= 4:
+ if l:
+ raise util.Abort(_("invalid chunk length %d") % l)
return ""
return readexactly(stream, l - 4)
@@ -149,11 +151,15 @@
return self._stream.close()
def chunklength(self):
- d = readexactly(self._stream, 4)
- l = max(0, struct.unpack(">l", d)[0] - 4)
- if l and self.callback:
+ d = readexactly(stream, 4)
+ l = struct.unpack(">l", d)[0]
+ if l <= 4:
+ if l:
+ raise util.Abort(_("invalid chunk length %d") % l)
+ return 0
+ if self.callback:
self.callback()
- return l
+ return l - 4
def chunk(self):
"""return the next chunk from changegroup 'source' as a string"""