# HG changeset patch # User Pierre-Yves David # Date 2014-03-18 23:35:34 # Node ID 88db3e6153196e2731a71f0044223659edf63b7e # Parent 520df53ad26a9105f5d4a7647243567bb7a0e697 bundle2: make sure the unbundler refuse non bundle2 stream We now make use of the magic string at the beginning of the file. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -62,7 +62,7 @@ Binary format is as follow import util import changegroup - +from i18n import _ _magicstring = 'HG20' @@ -93,10 +93,13 @@ class unbundle20(object): (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""" diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t --- a/tests/test-bundle2.t +++ b/tests/test-bundle2.t @@ -38,6 +38,9 @@ The extension requires a repo (currently $ hg init main $ cd main + $ touch a + $ hg add a + $ hg commit -m 'a' Test simple generation of empty bundle @@ -49,3 +52,11 @@ Test parsing of an empty bundle $ hg bundle2 | hg unbundle2 options count: 0 parts count: 0 + +Test old style bundle are detected and refused + + $ hg bundle --all ../bundle.hg + 1 changesets found + $ hg unbundle2 < ../bundle.hg + abort: unknown bundle version 10 + [255]