From b711c01e777977a4f9e2b78d7ab91f09f3fdf03f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 18 Jan 2012 00:40:38 +0100 Subject: improve error reporting in case of errors in combination with zlib --- apt-pkg/contrib/fileutl.cc | 20 +++++++++++++++----- apt-pkg/contrib/mmap.cc | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index b350973af..2bbf3a1b1 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -867,6 +867,7 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co else iFd = open(FileName.c_str(), fileflags, Perms); + this->FileName = FileName; if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false) { if (iFd != -1) @@ -877,7 +878,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co return _error->Errno("open",_("Could not open file %s"), FileName.c_str()); } - this->FileName = FileName; SetCloseExec(iFd,true); return true; } @@ -916,13 +916,13 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: d->openmode = Mode; Flags = (AutoClose) ? FileFd::AutoClose : 0; iFd = Fd; + this->FileName = ""; if (OpenInternDescriptor(Mode, compressor) == false) { if (AutoClose) close (iFd); return _error->Errno("gzdopen",_("Could not open file descriptor %d"), Fd); } - this->FileName = ""; return true; } bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor) @@ -1057,11 +1057,21 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) else #endif Res = read(iFd,To,Size); - if (Res < 0 && errno == EINTR) - continue; + if (Res < 0) { + if (errno == EINTR) + continue; Flags |= Fail; +#if APT_USE_ZLIB + if (d->gz != NULL) + { + int err; + char const * const errmsg = gzerror(d->gz, &err); + if (err != Z_ERRNO) + return _error->Error("gzread: %s (%d: %s)", _("Read error"), err, errmsg); + } +#endif return _error->Errno("read",_("Read error")); } @@ -1405,7 +1415,7 @@ bool FileFd::Close() #if APT_USE_ZLIB if (d != NULL && d->gz != NULL) { int const e = gzclose(d->gz); - // gzdopen() on empty files always fails with "buffer error" here, ignore that + // gzdclose() on empty files always fails with "buffer error" here, ignore that if (e != 0 && e != Z_BUF_ERROR) Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str()); } else diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index a67ab3698..160718ea5 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -85,7 +85,7 @@ bool MMap::Map(FileFd &Fd) return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str()); Base = new unsigned char[iSize]; if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false) - return false; + return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str()); return true; } -- cgit v1.2.3-70-g09d2 From 65c72a4b84273bf8063076bd74861b5931c2b8a5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 18 Jan 2012 00:51:03 +0100 Subject: * apt-pkg/contrib/fileutl.h: - store the offset in the internal fd before calculate size of the zlib-handled file to jump back to this place again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It jumped back to the position of the content - which is wrong as the internal fd is compressed and even reseting to the beginning of the file doesn't work as zlib uses an internal buffer, so while we might haven't read anything yet zlib might have done so already… --- apt-pkg/contrib/fileutl.cc | 4 +++- debian/changelog | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 2bbf3a1b1..28898fc34 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1347,6 +1347,7 @@ unsigned long long FileFd::Size() // gzopen in "direct" mode as well else if (d->gz && !gzdirect(d->gz) && size > 0) { + off_t const oldPos = lseek(iFd,0,SEEK_CUR); /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do * this ourselves; the original (uncompressed) file size is the last 32 * bits of the file */ @@ -1364,8 +1365,9 @@ unsigned long long FileFd::Size() size = tmp_size; #endif - if (lseek(iFd, d->seekpos, SEEK_SET) < 0) + if (lseek(iFd, oldPos, SEEK_SET) < 0) return _error->Errno("lseek","Unable to seek in gzipped file"); + return size; } #endif diff --git a/debian/changelog b/debian/changelog index 2e8bcfb13..c7c33fef1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,12 +9,15 @@ apt (0.8.16~exp10) UNRELEASED; urgency=low * apt-pkg/deb/dpkgpm.cc: - check if dpkg supports multiarch with --assert-multi-arch and if it does be always explicit about the architecture + * apt-pkg/contrib/fileutl.h: + - store the offset in the internal fd before calculate size of + the zlib-handled file to jump back to this place again [ Michael Vogt ] - * apt-pkg/contrib/fileutils.h: + * apt-pkg/contrib/fileutl.h: - fix segfault from python-apt testsuite - -- David Kalnischkies Fri, 13 Jan 2012 17:29:07 +0100 + -- David Kalnischkies Wed, 18 Jan 2012 00:47:54 +0100 apt (0.8.16~exp9) experimental; urgency=low -- cgit v1.2.3-70-g09d2