[PATCH 3 of 3] changegroup: don't accept odd chunk headers

Mads Kiilerich mads at kiilerich.com
Tue Feb 22 02:38:17 UTC 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1298340637 -3600
# Branch stable
# Node ID c8c285b557fdebc75a89db938db90daa771f2ee1
# Parent  3a48f75a76348e4471ab614082d4110220884589
changegroup: don't accept odd chunk headers

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -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"""



More information about the Mercurial-devel mailing list