commit 8d1ee06625bc6121b08173cd37abb63dfb14e99b
Author: Egmont Koblinger <egmont@gmail.com>
Date:   Sun Apr 26 19:18:33 2015 +0200

    try1

diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index bcd68df..92ac363 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -845,11 +845,6 @@ _vte_boa_reset (VteBoa *boa, gsize offset)
 {
         g_assert_cmpuint (offset % VTE_BOA_BLOCKSIZE, ==, 0);
 
-        /* _vte_ring_reset() is designed never to actually reset the logical offset.
-         * It's important for the encryption so that we don't reuse the same IV.
-         * Hence this is probably the best place to double check this. */
-        g_assert_cmpuint (offset, >=, boa->head);
-
         _vte_snake_reset (&boa->parent, OFFSET_BOA_TO_SNAKE(offset));
 
         boa->tail = boa->head = offset;
@@ -1437,6 +1432,14 @@ test_snake (void)
         g_object_unref (snake);
 }
 
+/* 10-byte blocks in the file and snake layers consist of:
+ * - 1 byte: length of the fake-compressed fake-encrypted payload (n)
+ * - 1 byte: overwrite counter for the given block
+ * - n bytes: fake-compressed fake-encrypted payload
+ * - 1 byte: fake checksum (5 bits: block sequence number, 3 bits: overwrite counter)
+ * - 7-n bytes: dots for padding
+ */
+
 static void
 test_boa (void)
 {
@@ -1706,6 +1709,29 @@ test_stream (void)
         assert_boa (boa, 175, 182, "zebraaa");
         assert_stream (astream, 175, 182, "zebraaa");
 
+        /* Bug 748484: cross-boundary truncate followed by a reset */
+        _vte_stream_truncate (astream, 178);
+        assert_file (snake->fd, "\007\001ZEBRAAA\311");
+        assert_snake (snake, 1, 250, 260, "\007\001ZEBRAAA\311");
+        assert_boa (boa, 175, 182, "zebraaa");
+        assert_stream (astream, 175, 178, "zeb");
+        _vte_stream_reset (astream, 178);
+        assert_file (snake->fd, "");
+        assert_snake (snake, 1, 250, 250, "");
+        assert_boa (boa, 175, 175, "");
+        assert_stream (astream, 178, 178, "");
+        stream_append (astream, "raaa");
+
+// These are bad, since the overwrite conter is not incremented.
+        assert_file (snake->fd, "\006\0013-1R3A\311.");
+        assert_snake (snake, 1, 250, 260, "\006\0013-1R3A\311.");
+// They should look like this instead:
+//        assert_file (snake->fd, "\006\0023-1R3A\312.");
+//        assert_snake (snake, 1, 250, 260, "\006\0023-1R3A\312.");
+
+        assert_boa (boa, 175, 182, "---raaa");
+        assert_stream (astream, 178, 182, "raaa");
+
         g_object_unref (astream);
 }
 
