comparison mercurial/changegroup.py @ 13456:ab3f4ee48adc stable

changegroup: don't accept streams without proper termination Streams should be terminated with a zero size changegroup, and read should never be permitted to return less than requested.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 22 Feb 2011 03:02:50 +0100
parents 6277a9469dff
children e74fe15dc7fd
comparison
equal deleted inserted replaced
13455:053c042118bc 13456:ab3f4ee48adc
10 import struct, os, bz2, zlib, tempfile 10 import struct, os, bz2, zlib, tempfile
11 11
12 def getchunk(source): 12 def getchunk(source):
13 """return the next chunk from changegroup 'source' as a string""" 13 """return the next chunk from changegroup 'source' as a string"""
14 d = source.read(4) 14 d = source.read(4)
15 if not d:
16 return ""
17 l = struct.unpack(">l", d)[0] 15 l = struct.unpack(">l", d)[0]
18 if l <= 4: 16 if l <= 4:
19 return "" 17 return ""
20 d = source.read(l - 4) 18 d = source.read(l - 4)
21 if len(d) < l - 4: 19 if len(d) < l - 4:
146 def close(self): 144 def close(self):
147 return self._stream.close() 145 return self._stream.close()
148 146
149 def chunklength(self): 147 def chunklength(self):
150 d = self.read(4) 148 d = self.read(4)
151 if not d:
152 return 0
153 l = max(0, struct.unpack(">l", d)[0] - 4) 149 l = max(0, struct.unpack(">l", d)[0] - 4)
154 if l and self.callback: 150 if l and self.callback:
155 self.callback() 151 self.callback()
156 return l 152 return l
157 153