Mercurial > hg-stable
changeset 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 |
files | mercurial/bundle2.py tests/test-bundle2.t |
diffstat | 2 files changed, 18 insertions(+), 4 deletions(-) [+] |
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"""
--- a/tests/test-bundle2.t Tue Mar 18 14:28:42 2014 -0700 +++ b/tests/test-bundle2.t Tue Mar 18 16:35:34 2014 -0700 @@ -38,6 +38,9 @@ $ hg init main $ cd main + $ touch a + $ hg add a + $ hg commit -m 'a' Test simple generation of empty bundle @@ -49,3 +52,11 @@ $ 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]