index-pack: Avoid disk corruption yielding a valid pack footer checksum
commit0ce562626aa05792ebbbdd9688cd3c2a0418319a
authorShawn O. Pearce <spearce@spearce.org>
Wed, 27 Aug 2008 21:48:43 +0000 (27 14:48 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 27 Aug 2008 22:12:19 +0000 (28 00:12 +0200)
tree52cba389a97bb416bc039962a39932b07fb08693
parent5d35ef22e9269476fb95276ba138489439f80e21
index-pack: Avoid disk corruption yielding a valid pack footer checksum

When we are processing a thin pack and making it non-thin we need
to update the header with a new object count.  That causes us to
recompute the footer checksum for the entire pack, and the only
way to do that is to re-read the data from disk.

If there was filesystem corruption in the process (e.g. a bad
disk sector, or a kernel bug) we don't want to produce a valid
pack at the end.  Instead we need to fail-fast with the error
so the user is aware of the corruption.

We now keep track of where the end of the original data is and
run two SHA-1 computations during the header-footer fixup.  If
the original data region doesn't match the original footer we
got over the network we know there was corruption and we just
cannot trust this pack file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java