add unit test for borked ciphertext size
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Mon, 28 Aug 2017 15:59:42 +0000 (17:59 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:09 +0000 (13:34 +0200)
runtests.py
testing/test_recover.py

index 146d6e4..a11ecdd 100755 (executable)
@@ -35,6 +35,7 @@ from testing.test_recover import \
     , RecoverCorruptHeaderGZMultiTest \
     , RecoverCorruptHeaderGZAESSingleTest \
     , RecoverCorruptHeaderGZAESMultiTest \
+    , RecoverCorruptHeaderCTSizeGZAESTest \
     , RecoverCorruptEntireHeaderSingleTest \
     , RecoverCorruptEntireHeaderMultiTest \
     , RecoverCorruptEntireHeaderGZSingleTest \
@@ -106,6 +107,7 @@ if __name__ == "__main__":
                          , RecoverCorruptHeaderGZMultiTest
                          , RecoverCorruptHeaderGZAESSingleTest
                          , RecoverCorruptHeaderGZAESMultiTest
+                         , RecoverCorruptHeaderCTSizeGZAESTest
                          , RecoverCorruptEntireHeaderSingleTest
                          , RecoverCorruptEntireHeaderMultiTest
                          , RecoverCorruptEntireHeaderGZSingleTest
index cd48a00..dbf2608 100644 (file)
@@ -84,6 +84,9 @@ def is_pdt_encrypted (fname):
 ## corruption simulators                                                     ##
 ###############################################################################
 
+class UndefinedTest (Exception):
+    """No test available for the asked combination of parameters."""
+
 def corrupt_header (_, fname, compress, encrypt):
     """
     Modify a significant byte in the object header of the format.
@@ -106,6 +109,19 @@ def corrupt_header (_, fname, compress, encrypt):
         flip_bits (fname, 100 + 8 + 8 + 8 + 12 + 12 + 1)
 
 
+def corrupt_ctsize (_, fname, compress, encrypt):
+    """
+    Blow up the size of an object so as to cause its apparent payload to leak
+    into the next one.
+    """
+    if encrypt is True:
+        # damage lowest bit of second least significant byte of size field;
+        # this effectively sets the ciphertext size to 422, causing it to
+        # extend over the next object into the third one.
+        return flip_bits (fname, crypto.HDR_OFF_CTSIZE + 1, b=0x01)
+    raise UndefinedTest ("corrupt_ctsize %s %s %s" % (fname, compress, encrypt))
+
+
 def corrupt_entire_header (_, fname, compress, encrypt):
     """
     Flip all bits in the first object header.
@@ -761,6 +777,15 @@ class RescueCorruptHoleGZAESTest (RescueCorruptHoleBaseTest):
     # to this point though
     FAILURES    = 1
 
+
+class RecoverCorruptHeaderCTSizeGZAESTest (RescueTest):
+    COMPRESSION = "#gz"
+    PASSWORD    = TEST_PASSWORD
+    FAILURES    = 0
+    CORRUPT     = corrupt_ctsize
+    MISMATCHES  = 0
+
+
 ###############################################################################
 # index
 ###############################################################################