--- duplicity-0.6.11/src/tarfile.py 2010-11-20 15:05:14.000000000 -0600 +++ /usr/local/lib/python2.6/dist-packages/duplicity/tarfile.py 2010-12-15 02:03:39.911422010 -0600 @@ -170,8 +170,8 @@ """ chk = 256 # chksum field is treated as blanks, # so the initial value is 8 * ord(" ") - for c in buf[:148]: chk += ord(c) # sum up all bytes before chksum - for c in buf[156:]: chk += ord(c) # sum up all bytes after chksum + for c in buf[:148+8]: chk += ord(c) # sum up all bytes before chksum + for c in buf[156+8:]: chk += ord(c) # sum up all bytes after chksum return chk def copyfileobj(src, dst, length=None): @@ -386,19 +386,19 @@ def getheader(self): """Return a tar header block as a 512 byte string. """ - if self.uid > 2097151 or self.uid < 0: - sys.stderr.write("uid %i of file %s not in range. Setting uid to 60001\n" % (self.uid,self.name)) - self.uid = 60001 - if self.gid > 2097151 or self.gid < 0: - sys.stderr.write("gid %i of file %s not in range. Setting gid to 60001\n" % (self.gid, self.name)) - self.gid = 60001 +# if self.uid > 2097151 or self.uid < 0: +# sys.stderr.write("uid %i of file %s not in range. Setting uid to 60001\n" % (self.uid,self.name)) +# self.uid = 60001 +# if self.gid > 2097151 or self.gid < 0: +# sys.stderr.write("gid %i of file %s not in range. Setting gid to 60001\n" % (self.gid, self.name)) +# self.gid = 60001 # The following code was contributed by Detlef Lannert. parts = [] for value, fieldsize in ( (self.name, 100), ("%07o" % self.mode, 8), - ("%07o" % self.uid, 8), - ("%07o" % self.gid, 8), + ("%011o" % self.uid, 12), + ("%011o" % self.gid, 12), ("%011o" % self.size, 12), ("%011o" % self.mtime, 12), (" ", 8), @@ -410,14 +410,15 @@ (self.gname, 32), ("%07o" % self.devmajor, 8), ("%07o" % self.devminor, 8), - (self.prefix, 155) + (self.prefix, 155-8) ): l = len(value) parts.append(value + (fieldsize - l) * "\0") buf = "".join(parts) chksum = calc_chksum(buf) - buf = buf[:148] + "%06o\0" % chksum + buf[155:] +# buf = buf[:148] + "%06o\0" % chksum + buf[155:] + buf = buf[:148+8] + "%06o\0" % chksum + buf[155+8:] buf += (512 - len(buf)) * "\0" self.buf = buf return buf @@ -1062,25 +1063,96 @@ """Transform a 512 byte block to a TarInfo instance. """ tarinfo = TarInfo() - tarinfo.name = nts(buf[0:100]) - tarinfo.mode = int(buf[100:107], 8) - tarinfo.uid = int(buf[108:115],8) - tarinfo.gid = int(buf[116:123],8) - tarinfo.size = long(buf[124:135], 8) - tarinfo.mtime = long(buf[136:147], 8) + x = 0 + step = 100 + tarinfo.name = nts(buf[x:x+step]) + + x += step + step = 7 + tarinfo.mode = int(buf[x:x+step], 8) + + # terminator + step += 1 + + x += step + step = 11 + tarinfo.uid = int(buf[x:x+step],8) + + # terminator + step += 1 + + x += step + step = 11 + tarinfo.gid = int(buf[x:x+step],8) + + # terminator + step += 1 + + x += step + step = 11 + tarinfo.size = long(buf[x:x+step], 8) + + # terminator + step += 1 + + x += step + step = 11 + tarinfo.mtime = long(buf[x:x+step], 8) + + # terminator + step += 1 + # chksum stored as a six digit octal number with # leading zeroes followed by a nul and then a space - tarinfo.chksum = int(buf[148:154], 8) - tarinfo.type = buf[156:157] - tarinfo.linkname = nts(buf[157:257]) - tarinfo.uname = nts(buf[265:297]) - tarinfo.gname = nts(buf[297:329]) + x += step + step = 6 + tarinfo.chksum = int(buf[x:x+step], 8) + + # terminator and space + step += 2 + + x += step + step = 1 + tarinfo.type = buf[x:x+step] + + x += step + step = 100 + tarinfo.linkname = nts(buf[x:x+step]) + + # skipped MAGIC (6), VERSION (2) + step += 8 + + x += step + step = 32 + tarinfo.uname = nts(buf[x:x+step]) + + x += step + step = 32 + tarinfo.gname = nts(buf[x:x+step]) + try: - tarinfo.devmajor = int(buf[329:336], 8) - tarinfo.devminor = int(buf[337:344], 8) + + x += step + step = 7 + tarinfo.devmajor = int(buf[x:x+step], 8) + + # terminator x + step += 1 + + x += step + step = 7 + tarinfo.devminor = int(buf[x:x+step], 8) + + # terminator x + step += 1 + except ValueError: tarinfo.devmajor = tarinfo.devmajor = 0 - tarinfo.prefix = buf[345:500] + + x += step + step = 155-8 + tarinfo.prefix = buf[x:x+step] + if tarinfo.chksum != calc_chksum(buf): self._dbg(1, "tarfile: Bad Checksum\n") return tarinfo @@ -1141,7 +1213,7 @@ """ buf = tarinfo.getheader() sp = _ringbuffer() - pos = 386 + pos = 386+8 lastpos = 0l realpos = 0l try: @@ -1157,8 +1229,8 @@ lastpos = offset + numbytes pos += 24 - isextended = ord(buf[482]) - origsize = int(buf[483:495], 8) + isextended = ord(buf[482+8]) + origsize = int(buf[483+8:495+8], 8) # If the isextended flag is given, # there are extra headers to process. @@ -1175,7 +1247,7 @@ realpos += numbytes lastpos = offset + numbytes pos += 24 - isextended = ord(buf[504]) + isextended = ord(buf[504+8]) except ValueError: pass if lastpos < origsize: