diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-04-26 11:39:48 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-04-26 12:00:49 +0200 |
commit | bee6a29198e7c8f6636aafece9a42c97435d171e (patch) | |
tree | f5540a2a918be54faf249649b1004720acafc664 /src | |
parent | caeab8f626e709569cc492b75eb7e119076059e7 (diff) |
journal-file: make seeking in corrupted files work
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/journal/journal-file.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index c97b3f9882..ff01e5aa94 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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; |