[PATCH 0/6] Handle and report decompression errors; handle multistream bzip2 files

Jon TURNEY jon.turney@dronecode.org.uk
Fri Apr 8 14:44:00 GMT 2011

On 31/03/2011 15:35, Jon TURNEY wrote:
> The first problem is that .bz2 file and the decompressor don't like each
> other. The decompressor reports the stream has ended partway through
> decompressing glxext.h.  It's very mysterious that it should fail but bunzip2
> has no problems with the same file.

The reason for this failure is that the pbzip compressed file contains multiple
compressed streams, which we need to decompress and concatenate to handle correctly.

While files like that can be made using bzip2 (merely by appending the output of
multiple runs), I don't think that tar -j will make one unless pbzip is in use.

On 31/03/2011 15:35, Jon TURNEY wrote:
> The second problem is a setup bug: If we get an unexpected short read from the
> archive stream decompressor, we'll sit in an infinite loop writing garbage to
> the output file 5 bytes at a time.  A patch is attached which fixes that, but
> since these errors are  unreported (see comment in io_stream::copy), we just
> stop expanding the archive, leaving an incomplete glxext.h

Silent failures are the devil's spawn, so I've done some more work to make it
so these failures can be reported to the user

On 31/03/2011 15:42, Eric Blake wrote:
> Would returning -EIO be better, since a negative value is a key that
> something went wrong besides normal end of file?

On reflection, I think that the correct thing to do is follow the model of POSIX
read() for all the io_stream derived classes read() method, returning 0 at EOF, o
returning -1 and setting the value returned by error() if an error occured.

I do not think that 5/6 and 6/6 should be applied without some serious review
and/or testing, as the possibilty that they break package installation in some way
needs to be balanced against the benefit of being able to use pbzip to make packages.

Jon TURNEY (6):
  Don't hang if something goes wrong reading from a tar archive
  Consistently return -1 and set lasterr instead in io_stream derived
  Propagate errors out of io_stream::copy()
  Report failure extracting a file from package to the user
  Handle bzip2 multi-stream files
  Handle short reads in archive_tar_file::read()

 archive.cc          |    2 +-
 archive_tar_file.cc |   58 ++++++++----
 compress_bz.cc      |   47 ++++++----
 compress_bz.h       |    1 -
 compress_gz.cc      |   20 ++++-
 install.cc          |  245 ++++++++++++++++++++++++++++++--------------------
 io_stream.cc        |   17 ++--
 7 files changed, 238 insertions(+), 152 deletions(-)


More information about the Cygwin-apps mailing list