From 5dd0df0162b2dca58f4b3c650bbb46ae06a3adf8 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 11 Aug 2018 22:47:01 +0200 Subject: [PATCH] cache: Remove files from cache which are too small --- internal/cache/file.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/cache/file.go b/internal/cache/file.go index f232bc7c1..32ad237bf 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -63,6 +63,12 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, return nil, errors.Errorf("cached file %v is truncated, removing", h) } + if fi.Size() < offset+int64(length) { + _ = f.Close() + _ = c.Remove(h) + return nil, errors.Errorf("cached file %v is too small, removing", h) + } + if offset > 0 { if _, err = f.Seek(offset, io.SeekStart); err != nil { _ = f.Close()