Detect short reads - dedup - deduplicating backup program HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit f08d3792bd0dc9154b8a0e09b339d9d80845b71f DIR parent d0cf858ff772267664f2286a69e133972f00520d HTML Author: sin <sin@2f30.org> Date: Thu, 7 Mar 2019 17:17:51 +0000 Detect short reads This can happen if the store is truncated. Diffstat: M dedup.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- DIR diff --git a/dedup.c b/dedup.c @@ -211,9 +211,14 @@ hash_blk(uint8_t *buf, size_t size, uint8_t *md) static void read_blk(uint8_t *buf, struct blk_desc *blk_desc) { + ssize_t n; + xlseek(sfd, blk_desc->offset, SEEK_SET); - if (xread(sfd, buf, blk_desc->size) == 0) - errx(1, "read: unexpected EOF"); + n = xread(sfd, buf, blk_desc->size); + if (n == 0) + errx(1, "read_blk: unexpected EOF"); + if (n != blk_desc->size) + errx(1, "read_blk: short read"); } static void