From 94f6210b685cba115f45c2e580d8047c8cba23bc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 9 Feb 2021 22:15:33 -0400 Subject: [PATCH] deal with possibility of short read by S.hGet It may read less than requested, and may yield an empty string if the file was somehow shorter than expected. --- P2P/Annex.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/P2P/Annex.hs b/P2P/Annex.hs index c28c3eba71..e039f67a4e 100644 --- a/P2P/Annex.hs +++ b/P2P/Annex.hs @@ -172,11 +172,14 @@ runLocal runst runner a = case a of where go iv n | n == 0 = return () - | n > fromIntegral defaultChunkSize = do - updateIncremental iv =<< S.hGet h defaultChunkSize - go iv (n - fromIntegral defaultChunkSize) - | otherwise = - updateIncremental iv =<< S.hGet h (fromIntegral n) + | otherwise = do + let c = if n > fromIntegral defaultChunkSize + then defaultChunkSize + else fromIntegral n + b <- S.hGet h c + updateIncremental iv b + unless (b == S.empty) $ + go iv (n - fromIntegral (S.length b)) storefile dest (Offset o) (Len l) getb incrementalverifier validitycheck p ti = do v <- runner getb