[tracker/binary-log-2: 24/46] Fixed journal crc check failure



commit 1e59a216dd036c1a2788d57bbb75e9e398070a11
Author: Martyn Russell <martyn lanedo com>
Date:   Wed Jan 6 10:40:48 2010 +0000

    Fixed journal crc check failure

 src/libtracker-db/tracker-db-journal.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 73e8ccf..06957c9 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -648,7 +648,8 @@ tracker_db_journal_reader_next (GError **error)
 		/* Expect new transaction or end of file */
 		guint32 entry_size;
 		guint32 entry_size_check;
-		guint32 crc32;
+		guint32 crc;
+		guint32 crc_check;
 
 		/* Check the end is not before where we currently are */
 		if (reader.current >= reader.end) {
@@ -671,7 +672,7 @@ tracker_db_journal_reader_next (GError **error)
 		entry_size = read_uint32 (reader.current);
 
 		/* Set the bounds for the entry */
-		reader.entry_begin = reader.current;
+		reader.entry_begin = reader.current + (sizeof (guint32) * 3);
 		reader.entry_end = reader.entry_begin + entry_size;
 
 		/* Check the end of the entry does not exceed the end
@@ -688,7 +689,7 @@ tracker_db_journal_reader_next (GError **error)
 		 */
 		reader.current += 4;
 
-		/* compare with entry_size at end */
+		/* Read entry size check at the end of the entry */
 		entry_size_check = read_uint32 (reader.entry_end - 4);
 
 		if (entry_size != entry_size_check) {
@@ -700,17 +701,24 @@ tracker_db_journal_reader_next (GError **error)
 			return FALSE;
 		}
 
+		/* Read the amount of triples */
 		reader.amount_of_triples = read_uint32 (reader.current);
 		reader.current += 4;
 
-		crc32 = read_uint32 (reader.current);
+		/* Read the crc */
+		crc_check = read_uint32 (reader.current);
 		reader.current += 4;
 
-		/* verify checksum */
-		if (crc32 != tracker_crc32 (reader.entry_begin, entry_size)) {
+		/* Calculate the crc */
+		crc = tracker_crc32 (reader.entry_begin, entry_size);
+
+		/* Verify checksum */
+		if (crc != crc_check) {
 			/* damaged journal entry */
 			g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0, 
-			             "Damaged journal entry, crc32 failed");
+			             "Damaged journal entry, 0x%.8x != 0x%.8x (crc32 failed)",
+			             crc,
+			             crc_check);
 			return FALSE;
 		}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]