# HG changeset patch # User Pierre-Yves David # Date 1413368845 25200 # Node ID 006a81d07e579792f7e2eb92c472d1e66887ac96 # Parent 73f394f4affcc141b2cce3cfcea7a11c0965e05b bundle2: detect and disallow a negative chunk size We have no usage planned for 2/3 of them and the support for the planned usecase is not here yet. So we raise a BundleValueError when encountered diff -r 73f394f4affc -r 006a81d07e57 mercurial/bundle2.py --- a/mercurial/bundle2.py Wed Oct 15 03:22:47 2014 -0700 +++ b/mercurial/bundle2.py Wed Oct 15 03:27:25 2014 -0700 @@ -509,6 +509,9 @@ self.ui.debug('reading bundle2 stream parameters\n') params = {} paramssize = self._unpack(_fstreamparamsize)[0] + if paramssize < 0: + raise error.BundleValueError('negative bundle param size: %i' + % paramssize) if paramssize: for p in self._readexact(paramssize).split(' '): p = p.split('=', 1) @@ -558,6 +561,9 @@ returns None if empty""" headersize = self._unpack(_fpartheadersize)[0] + if headersize < 0: + raise error.BundleValueError('negative part header size: %i' + % headersize) self.ui.debug('part header size: %i\n' % headersize) if headersize: return self._readexact(headersize) @@ -765,6 +771,9 @@ payloadsize = self._unpack(_fpayloadsize)[0] self.ui.debug('payload chunk size: %i\n' % payloadsize) while payloadsize: + if payloadsize < 0: + msg = 'negative payload chunk size: %i' % payloadsize + raise error.BundleValueError(msg) yield self._readexact(payloadsize) payloadsize = self._unpack(_fpayloadsize)[0] self.ui.debug('payload chunk size: %i\n' % payloadsize)