summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 52b9bfbe6..b43771ea7 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -105,11 +105,16 @@ bool Hashes::AddFD(int Fd,unsigned long Size)
{
unsigned char Buf[64*64];
int Res = 0;
- while (Size != 0)
+ int ToEOF = (Size == 0);
+ while (Size != 0 || ToEOF)
{
- Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
- if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
- return false;
+ unsigned n = sizeof(Buf);
+ if (!ToEOF) n = min(Size,(unsigned long)n);
+ Res = read(Fd,Buf,n);
+ if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
+ return false;
+ if (ToEOF && Res == 0) // EOF
+ break;
Size -= Res;
MD5.Add(Buf,Res);
SHA1.Add(Buf,Res);