~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Robert Collins
  • Date: 2006-04-18 04:22:52 UTC
  • mto: (1711.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1667.
  • Revision ID: robertc@robertcollins.net-20060418042252-d0cad40d7c5dcb6a
Fix race condition between end of stream and end of file with tuned_gzip.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
            # (The number of bytes to seek back is the length of the unused
110
110
            # data, minus 8 because those 8 bytes are part of this member.
111
111
            seek_length = len (self.decompress.unused_data) - 8
112
 
            if seek_length:
113
 
                assert seek_length > 0
 
112
            if seek_length > 0:
 
113
                # we read too much data
114
114
                self.fileobj.seek(-seek_length, 1)
 
115
            elif seek_length < 0:
 
116
                # we haven't read enough to check the checksum.
 
117
                assert -8 < seek_length, "too great a seek."
 
118
                buf = self.fileobj.read(-seek_length)
 
119
                self.decompress.decompress(buf)
115
120
 
116
121
            # Check the CRC and file size, and set the flag so we read
117
122
            # a new member on the next call
135
140
        crc32, isize = struct.unpack("<LL", self.decompress.unused_data[0:8])
136
141
        # note that isize is unsigned - it can exceed 2GB
137
142
        if crc32 != U32(self.crc):
138
 
            raise IOError, "CRC check failed"
 
143
            raise IOError, "CRC check failed %d %d" % (crc32, U32(self.crc))
139
144
        elif isize != LOWU32(self.size):
140
145
            raise IOError, "Incorrect length of data produced"
141
146