]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file: make seeking in corrupted files work
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Apr 2016 09:39:48 +0000 (11:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 26 Apr 2016 10:00:49 +0000 (12:00 +0200)
Previously, when we used a bisection table for seeking through a corrupted
file, and the end of the bisection table was corrupted we'd most likely fail
the entire seek operation. Improve the situation: if we encounter invalid
entries in a bisection table, linearly go backwards until we find a working
entry again.

src/journal/journal-file.c

index c97b3f98828f7a63cf8d610beed7eed98cc3a8bd..ff01e5aa943af22dd19ed96b2969b8f132949eed 100644 (file)
@@ -1984,9 +1984,14 @@ static int generic_array_bisect(
                 i = right - 1;
                 lp = p = le64toh(array->entry_array.items[i]);
                 if (p <= 0)
-                        return -EBADMSG;
-
-                r = test_object(f, p, needle);
+                        r = -EBADMSG;
+                else
+                        r = test_object(f, p, needle);
+                if (r == -EBADMSG) {
+                        log_debug_errno(r, "Encountered invalid entry while bisecting, cutting algorithm short. (1)");
+                        n = i;
+                        continue;
+                }
                 if (r < 0)
                         return r;
 
@@ -2062,9 +2067,14 @@ static int generic_array_bisect(
 
                                 p = le64toh(array->entry_array.items[i]);
                                 if (p <= 0)
-                                        return -EBADMSG;
-
-                                r = test_object(f, p, needle);
+                                        r = -EBADMSG;
+                                else
+                                        r = test_object(f, p, needle);
+                                if (r == -EBADMSG) {
+                                        log_debug_errno(r, "Encountered invalid entry while bisecting, cutting algorithm short. (2)");
+                                        right = n = i;
+                                        continue;
+                                }
                                 if (r < 0)
                                         return r;