comparison mercurial/bundle2.py @ 23011:006a81d07e57

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
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 15 Oct 2014 03:27:25 -0700
parents 73f394f4affc
children 149fc8a44184
comparison
equal deleted inserted replaced
23010:73f394f4affc 23011:006a81d07e57
507 def params(self): 507 def params(self):
508 """dictionary of stream level parameters""" 508 """dictionary of stream level parameters"""
509 self.ui.debug('reading bundle2 stream parameters\n') 509 self.ui.debug('reading bundle2 stream parameters\n')
510 params = {} 510 params = {}
511 paramssize = self._unpack(_fstreamparamsize)[0] 511 paramssize = self._unpack(_fstreamparamsize)[0]
512 if paramssize < 0:
513 raise error.BundleValueError('negative bundle param size: %i'
514 % paramssize)
512 if paramssize: 515 if paramssize:
513 for p in self._readexact(paramssize).split(' '): 516 for p in self._readexact(paramssize).split(' '):
514 p = p.split('=', 1) 517 p = p.split('=', 1)
515 p = [urllib.unquote(i) for i in p] 518 p = [urllib.unquote(i) for i in p]
516 if len(p) < 2: 519 if len(p) < 2:
556 def _readpartheader(self): 559 def _readpartheader(self):
557 """reads a part header size and return the bytes blob 560 """reads a part header size and return the bytes blob
558 561
559 returns None if empty""" 562 returns None if empty"""
560 headersize = self._unpack(_fpartheadersize)[0] 563 headersize = self._unpack(_fpartheadersize)[0]
564 if headersize < 0:
565 raise error.BundleValueError('negative part header size: %i'
566 % headersize)
561 self.ui.debug('part header size: %i\n' % headersize) 567 self.ui.debug('part header size: %i\n' % headersize)
562 if headersize: 568 if headersize:
563 return self._readexact(headersize) 569 return self._readexact(headersize)
564 return None 570 return None
565 571
763 ## part payload 769 ## part payload
764 def payloadchunks(): 770 def payloadchunks():
765 payloadsize = self._unpack(_fpayloadsize)[0] 771 payloadsize = self._unpack(_fpayloadsize)[0]
766 self.ui.debug('payload chunk size: %i\n' % payloadsize) 772 self.ui.debug('payload chunk size: %i\n' % payloadsize)
767 while payloadsize: 773 while payloadsize:
774 if payloadsize < 0:
775 msg = 'negative payload chunk size: %i' % payloadsize
776 raise error.BundleValueError(msg)
768 yield self._readexact(payloadsize) 777 yield self._readexact(payloadsize)
769 payloadsize = self._unpack(_fpayloadsize)[0] 778 payloadsize = self._unpack(_fpayloadsize)[0]
770 self.ui.debug('payload chunk size: %i\n' % payloadsize) 779 self.ui.debug('payload chunk size: %i\n' % payloadsize)
771 self._payloadstream = util.chunkbuffer(payloadchunks()) 780 self._payloadstream = util.chunkbuffer(payloadchunks())
772 # we read the data, tell it 781 # we read the data, tell it