qforeign-0.65: Bzip2: decompress hangs if data ends prematurely

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
Thu, 25 Oct 2001 17:30:20 +0000 (UTC)


Thu, 25 Oct 2001 12:06:53 +0200 (CEST), Michael Marte <marte@pms.informatik.uni-muenchen.de> pisze:

> I found that decompress hangs if data ends prematurely, i.e.
> 
> 	do
> 	content <- readFile fp
> 	doSomething (Bzip2.decompress content)
> 
> does not terminate in this case.

Try this patch (sorry, untested):

--- examples/Bzip2.hsc~	Mon Jun 11 23:19:50 2001
+++ examples/Bzip2.hsc	Thu Oct 25 17:55:19 2001
@@ -169,6 +169,7 @@
     let blockIn = take blockSize input
     ok <- decompressBlock strm blockIn blockSize
     case ok of
+        RunOk 0      []       -> ioError (userError "bzip2: premature end of compressed data")
         RunOk inSize blockOut -> liftM (blockOut++) $ unsafeInterleaveIO $
                                      decompressLoop strm (drop inSize input)
         StreamEnd output      -> return output

It's in CVS at SourceForge now.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK