diff mercurial/bundle2.py @ 20803:88db3e615319

bundle2: make sure the unbundler refuse non bundle2 stream We now make use of the magic string at the beginning of the file.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 18 Mar 2014 16:35:34 -0700
parents 520df53ad26a
children db9d3991d2c6
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Mar 18 14:28:42 2014 -0700
+++ b/mercurial/bundle2.py	Tue Mar 18 16:35:34 2014 -0700
@@ -62,7 +62,7 @@
 
 import util
 import changegroup
-
+from i18n import _
 
 _magicstring = 'HG20'
 
@@ -93,10 +93,13 @@
     (this will eventually yield parts)"""
 
     def __init__(self, fp):
-        # assume the magic string is ok and drop it
-        # to be obviously fixed soon.
         self._fp = fp
-        self._readexact(4)
+        header = self._readexact(4)
+        magic, version = header[0:2], header[2:4]
+        if magic != 'HG':
+            raise util.Abort(_('not a Mercurial bundle'))
+        if version != '20':
+            raise util.Abort(_('unknown bundle version %s') % version)
 
     def _unpack(self, format):
         """unpack this struct format from the stream"""