changeset 13458:9f2c407caf34 stable

changegroup: don't accept odd chunk headers
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 22 Feb 2011 03:10:37 +0100
parents e74fe15dc7fd
children acbe171c8fbe
files mercurial/changegroup.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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"""