From 74d90653e0788d9e6e73a9427fa4fe6decaad843 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 11 May 2024 00:18:11 +0200 Subject: [PATCH] check: use ReadFull to load pack header in checkPack This ensures that the pack header is actually read completely. Previously, for a truncated file it was possible to only read a part of the header, as backend.Load(...) is not guaranteed to return as many bytes as requested by the length parameter. --- internal/checker/checker.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 1cee4355c..d6474f86e 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -605,11 +605,13 @@ func checkPackInner(ctx context.Context, r restic.Repository, id restic.ID, blob if err != nil { return &partialReadError{err} } + curPos += minHdrStart - curPos } // read remainder, which should be the pack header var err error - hdrBuf, err = io.ReadAll(bufRd) + hdrBuf = make([]byte, int(size-int64(curPos))) + _, err = io.ReadFull(bufRd, hdrBuf) if err != nil { return &partialReadError{err} }