summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/md5.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/md5.cc')
-rw-r--r--apt-pkg/contrib/md5.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc
index a095f8f0f..2bfd70f1b 100644
--- a/apt-pkg/contrib/md5.cc
+++ b/apt-pkg/contrib/md5.cc
@@ -294,11 +294,16 @@ bool MD5Summation::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;
Add(Buf,Res);
}