, RecoverCorruptHeaderGZMultiTest \
, RecoverCorruptHeaderGZAESSingleTest \
, RecoverCorruptHeaderGZAESMultiTest \
- , RecoverCorruptHeaderCTSizeGZAESTest \
+ , RescueCorruptHeaderCTSizeGZAESTest \
, RecoverCorruptEntireHeaderSingleTest \
, RecoverCorruptEntireHeaderMultiTest \
, RecoverCorruptEntireHeaderGZSingleTest \
, RecoverCorruptEntireHeaderGZMultiTest \
, RecoverCorruptEntireHeaderGZAESSingleTest \
, RecoverCorruptEntireHeaderGZAESMultiTest \
+ , RescueCorruptLeadingGarbageSingleTest \
+ , RescueCorruptLeadingGarbageMultiTest \
, RecoverCorruptTrailingDataSingleTest \
, RecoverCorruptTrailingDataMultiTest \
, RecoverCorruptTrailingDataGZSingleTest \
, RecoverCorruptHeaderGZMultiTest
, RecoverCorruptHeaderGZAESSingleTest
, RecoverCorruptHeaderGZAESMultiTest
- , RecoverCorruptHeaderCTSizeGZAESTest
+ , RescueCorruptHeaderCTSizeGZAESTest
, RecoverCorruptEntireHeaderSingleTest
, RecoverCorruptEntireHeaderMultiTest
, RecoverCorruptEntireHeaderGZSingleTest
, RecoverCorruptEntireHeaderGZMultiTest
, RecoverCorruptEntireHeaderGZAESSingleTest
, RecoverCorruptEntireHeaderGZAESMultiTest
+ , RescueCorruptLeadingGarbageSingleTest
+ , RescueCorruptLeadingGarbageMultiTest
, RecoverCorruptTrailingDataSingleTest
, RecoverCorruptTrailingDataMultiTest
, RecoverCorruptTrailingDataGZSingleTest
flip_bits (fname, tarfile.BLOCKSIZE + 1)
+def corrupt_leading_garbage (_, fname, compress, encrypt):
+ """
+ Prepend junk to file.
+ """
+ aname = os.path.abspath (fname)
+ infd = os.open (fname, os.O_RDONLY)
+ size = os.lseek (infd, 0, os.SEEK_END)
+ assert os.lseek (infd, 0, os.SEEK_SET) == 0
+ outfd = os.open (os.path.dirname (aname), os.O_WRONLY | os.O_TMPFILE,
+ stat.S_IRUSR | stat.S_IWUSR)
+ junk = os.urandom (512) # tar block sized
+
+ # write new file with garbage prepended
+ done = 0
+ os.write (outfd, junk) # junk first
+ done += len (junk)
+ while done < size:
+ data = os.read (infd, TEST_BLOCKSIZE)
+ os.write (outfd, data)
+ done += len (data)
+
+ assert os.lseek (outfd, 0, os.SEEK_CUR) == done
+
+ # close and free old file
+ os.close (infd)
+ os.unlink (fname)
+
+ # install the new file in its place, atomically
+ path = "/proc/self/fd/%d" % outfd
+ os.link (path, aname, src_dir_fd=0, follow_symlinks=True)
+ os.close (outfd)
+
+
def corrupt_trailing_data (_, fname, compress, encrypt):
"""
Modify the byte following the object header structure of the format.
outfd = os.open (os.path.dirname (aname), os.O_WRONLY | os.O_TMPFILE,
stat.S_IRUSR | stat.S_IWUSR)
- zeros = bytes (b'\x00' * TEST_BLOCKSIZE)
done = 0
while done < size:
data = os.read (infd, TEST_BLOCKSIZE)
FAILURES = 1
-class RecoverCorruptHeaderCTSizeGZAESTest (RescueTest):
+class RescueCorruptHeaderCTSizeGZAESTest (RescueTest):
COMPRESSION = "#gz"
PASSWORD = TEST_PASSWORD
FAILURES = 0
MISMATCHES = 0
+class RescueCorruptLeadingGarbageTestBase (RescueTest):
+ # plain Tar is indifferent against traling data and the results
+ # are consistent
+ COMPRESSION = None
+ PASSWORD = None
+ FAILURES = 0
+ CORRUPT = corrupt_leading_garbage
+ MISMATCHES = 0
+
+class RescueCorruptLeadingGarbageSingleTest (RescueCorruptLeadingGarbageTestBase):
+ VOLUMES = 1
+
+class RescueCorruptLeadingGarbageMultiTest (RescueCorruptLeadingGarbageTestBase):
+ # the last object in first archive has extra bytes somewhere in the
+ # middle because tar itself performs no data checksumming.
+ MISMATCHES = 2
+ VOLUMES = 3
+
+
###############################################################################
# index
###############################################################################