Bug#291338: apt: md5/sha1 checksum routines should work if length of file is unknown
Package: apt
Version: 0.5.4
Severity: wishlist
Tags: patch
SHA1Summation::AddFD should work on pipes as well as regular files
so files don't need to be uncompressed to disk to be summed. This
impacts python-apt too, since it doesn't offer a cumulative interface
to SHA1Summation.
Easy fix seems like it'd be:
bool SHA1Summation::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,sizeof(Buf)));
- if (Res < 0 || (unsigned) Res != MIN(Size,sizeof(Buf)))
+ int n = sizeof(Buf);
+ if (!ToEOF) n = MIN(Size,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);
}
return true;
}
-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux newraff 2.4.28-es #1 SMP Wed Jan 12 09:55:22 EST 2005 i686
Locale: LANG=C, LC_CTYPE=C
Versions of packages apt depends on:
ii libc6 2.2.5-11.8 GNU C Library: Shared libraries an
ii libstdc++2.10-glibc2.2 1:2.95.4-11woody1 The GNU stdc++ library
Reply to: