Add public API for fsck, use it before loading metadata

A while ago I did `truncate -s 0 /path/to/repo/00/123.commit`, and expected a
checksum error, but I actually got a validation error due to us loading the
commit into a variant and trying to parse out the parent checksum, etc.

I first started by changing the `load_and_fsck_one_object()` function to
checksum before loading, but the problem is that we do a traverse of all objects
first. Fixing this is going to require an `OSTREE_REPO_COMMIT_TRAVER_FLAG_FSCK`
or something.

In the meantime at least though, let's add a public API to fsck a single object
which *does* checksum cleanly before parsing the object, and change the `fsck`
command to use it.

We then change the fsck binary to do this while iterating over the refs
and finding the commit object.  This way we'll at least get a checksum
first for commit objects, even if not dirtree/dirmeta.

Closes: #1364
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-12-12 14:03:09 +00:00
1 parent 102f30f6cc
commit 73d910e82e
8 files changed
+160 -106

No files matched your search

+1 -1
View File
@@ -183,7 +183,7 @@ if ! skip_one_without_user_xattrs; then
if ${CMD_PREFIX} ostree --repo=cacherepo fsck 2>err.txt; then
fatal "corrupt repo fsck?"
fi
assert_file_has_content err.txt "corrupted.*${checksum}"
assert_file_has_content err.txt "Corrupted.*${checksum}"
rm ostree-srv/corruptrepo -rf
ostree_repo_init ostree-srv/corruptrepo --mode=archive
${CMD_PREFIX} ostree --repo=ostree-srv/corruptrepo pull-local cacherepo main
+14 -2
View File
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
# Copyright (C) 2011,2017 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
set -euo pipefail
echo "1..3"
echo "1..4"
. $(dirname $0)/libtest.sh
@@ -35,6 +35,18 @@ $OSTREE fsck -q
echo "ok chmod"
cd ${test_tmpdir}
rm repo files -rf
setup_test_repository "bare"
rev=$($OSTREE rev-parse test2)
echo -n > repo/objects/${rev:0:2}/${rev:2}.commit
if $OSTREE fsck -q 2>err.txt; then
fatal "fsck unexpectedly succeeded"
fi
assert_file_has_content_literal err.txt "Corrupted commit object; checksum expected"
echo "ok metadata checksum"
cd ${test_tmpdir}
rm repo files -rf
setup_test_repository "bare"
+1 -1
View File
@@ -76,7 +76,7 @@ if ! skip_one_without_user_xattrs; then
if ${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo fsck 2>err.txt; then
assert_not_reached "fsck with corrupted commit worked?"
fi
assert_file_has_content err.txt "corrupted object ${corruptrev}\.commit"
assert_file_has_content_literal err.txt "Corrupted commit object; checksum expected='${corruptrev}' actual='${rev}'"
# Do a pull-local; this should succeed since we don't verify checksums
# for local repos by default.