in contrib/server-side/fsfsverify.py [0:0]
def __init__(self, byteStream, svndiffVersion):
if svndiffVersion not in [0, 1]:
raise InvalidSvndiffVersion, \
"Invalid svndiff version %d" % svndiffVersion
# Record the initial offset of the window
self.windowOffset = byteStream.tell()
try:
self.sourceOffset = getVarint(byteStream)
self.sourceLength = getVarint(byteStream)
self.targetLength = getVarint(byteStream)
self.instrLength = getVarint(byteStream)
self.dataLength = getVarint(byteStream)
self.windowHeaderLength = byteStream.tell() - self.windowOffset
self.windowLength = \
self.windowHeaderLength + self.instrLength + self.dataLength
# Store the byte stream, and clone it for use as a data stream.
self.instrByteStream = byteStream
self.dataByteStream = byteStream.clone()
# Advance the data stream past the instructions to the start of the data.
self.dataByteStream.advance(self.instrLength)
except:
e = InvalidWindow(
"The window header at offset %d appears to be corrupted" % \
(self.windowOffset),
self.windowOffset)
e.windowOffset = self.windowOffset
raise e
# In svndiff1, the instruction area starts with a varint-encoded length.
# If this length matches the one encoded in the header, then there is no
# compression. If it differs, then the stream is compressed with zlib.
self.origInstrStream = self.instrByteStream
self.origDataStream = self.dataByteStream
self.isInstrCompressed = False
self.isDataCompressed = False
self.compressedInstrLength = self.instrLength
self.compressedDataLength = self.dataLength
if svndiffVersion == 1:
try:
offset = self.instrByteStream.tell()
encodedInstrLength = getVarint(self.instrByteStream)
instrIntSize = self.instrByteStream.tell() - offset
offset = self.dataByteStream.tell()
encodedDataLength = getVarint(self.dataByteStream)
dataIntSize = self.dataByteStream.tell() - offset
self.instrLength = encodedInstrLength
self.dataLength = encodedDataLength
except:
e = InvalidWindow(
"The window header at offset %d appears to be corrupted" % \
(self.windowOffset),
self.windowOffset)
e.windowOffset = self.windowOffset
raise e
# Now, we need to make a determination about whether the data and
# instructions are compressed. If they are, we need to zlib decompress
# them. We do that by creating another stream and that will decompress
# the data on the fly.
try:
offset = self.instrByteStream.tell()
if self.compressedInstrLength - instrIntSize != self.instrLength:
self.origInstrStream = self.instrByteStream
self.instrByteStream = ZlibByteStream(self.origInstrStream,
self.compressedInstrLength)
self.isInstrCompressed = True
except Exception as e:
new_e = InvalidCompressedStream(
"Invalid compressed instr stream at offset %d (%s)" % (offset,
str(e)),
offset)
new_e.windowOffset = self.windowOffset
raise new_e
try:
offset = self.dataByteStream.tell()
if self.compressedDataLength - dataIntSize != self.dataLength:
self.origDataStream = self.dataByteStream
self.dataByteStream = ZlibByteStream(self.origDataStream,
self.compressedDataLength)
self.isDataCompressed = True
except Exception as e:
new_e = InvalidCompressedStream(
"Invalid compressed data stream at offset %d (%s, %s)\n" % (
offset, str(e), repr(self)),
offset)
new_e.windowOffset = self.windowOffset
raise new_e