diff --git a/Codec/Compression/BZip.hs b/Codec/Compression/BZip.hs
--- a/Codec/Compression/BZip.hs
+++ b/Codec/Compression/BZip.hs
@@ -1,9 +1,9 @@
 -----------------------------------------------------------------------------
 -- |
--- Copyright   :  (c) 2006 Duncan Coutts
+-- Copyright   :  (c) 2006-2008 Duncan Coutts
 -- License     :  BSD-style
 --
--- Maintainer  :  duncan.coutts@worc.ox.ac.uk
+-- Maintainer  :  duncan@haskell.org
 -- Stability   :  provisional
 -- Portability :  portable (H98 + FFI)
 --
@@ -20,8 +20,8 @@
 module Codec.Compression.BZip (
 
   -- | This module provides pure functions for compressing and decompressing
-  -- streams of data represented by lazy 'ByteString's. This makes it easy to
-  -- use either in memory or with disk or network IO.
+  -- streams of data in the bzip2 format represented by lazy 'ByteString's.
+  -- This makes it easy to use either in memory or with disk or network IO.
   --
   -- For example a simple bzip compression program is just:
   --
@@ -35,19 +35,28 @@
   -- > content <- fmap BZip.decompress (readFile file)
   --
 
-  -- * Compression
+  -- * Simple compression and decompression
   compress,
+  decompress,
+
+  -- * Extended api with control over compression parameters
   compressWith,
-  BlockSize(..),
+  decompressWith,
 
-  -- * Decompression
-  decompress
+  CompressParams(..), defaultCompressParams,
+  DecompressParams(..), defaultDecompressParams,
 
+  -- ** The compression parameter types
+  BlockSize(..),
+  WorkFactor(..),
+  MemoryLevel(..),
+
   ) where
 
 import Data.ByteString.Lazy (ByteString)
 
-import Codec.Compression.BZip.Internal as Internal
+import qualified Codec.Compression.BZip.Internal as Internal
+import Codec.Compression.BZip.Internal hiding (compress, decompress)
 
 
 -- | Decompress a stream of data in the bzip2 format.
@@ -68,9 +77,18 @@
 -- stream before doing any IO action that depends on it.
 --
 decompress :: ByteString -> ByteString
-decompress = Internal.decompressDefault
+decompress = Internal.decompress defaultDecompressParams
 
 
+-- | Like 'decompress' but with the ability to specify various decompression
+-- parameters. Typical usage:
+--
+-- > decompressWith defaultCompressParams { ... }
+--
+decompressWith :: DecompressParams -> ByteString -> ByteString
+decompressWith = Internal.decompress
+
+
 -- | Compress a stream of data into the bzip2 format.
 --
 -- This uses the default compression level which uses the largest compression
@@ -78,11 +96,17 @@
 -- the compression block size.
 --
 compress :: ByteString -> ByteString
-compress = Internal.compressDefault DefaultBlockSize
+compress = Internal.compress defaultCompressParams
 
 
--- | Like 'compress' but with an extra parameter to specify the block size
--- used for compression.
+-- | Like 'compress' but with the ability to specify compression parameters.
+-- Typical usage:
 --
-compressWith :: BlockSize -> ByteString -> ByteString
-compressWith = Internal.compressDefault
+-- > compressWith defaultCompressParams { ... }
+--
+-- In particular you can set the compression block size:
+--
+-- > compressWith defaultCompressParams { compressBlockSize = BlockSize 1 }
+--
+compressWith :: CompressParams -> ByteString -> ByteString
+compressWith = Internal.compress
diff --git a/Codec/Compression/BZip/Internal.hs b/Codec/Compression/BZip/Internal.hs
--- a/Codec/Compression/BZip/Internal.hs
+++ b/Codec/Compression/BZip/Internal.hs
@@ -1,9 +1,10 @@
+{-# LANGUAGE CPP #-}
 -----------------------------------------------------------------------------
 -- |
--- Copyright   :  (c) 2006-2007 Duncan Coutts
+-- Copyright   :  (c) 2006-2008 Duncan Coutts
 -- License     :  BSD-style
 --
--- Maintainer  :  duncan.coutts@worc.ox.ac.uk
+-- Maintainer  :  duncan@haskell.org
 -- Stability   :  provisional
 -- Portability :  portable (H98 + FFI)
 --
@@ -12,18 +13,20 @@
 -----------------------------------------------------------------------------
 module Codec.Compression.BZip.Internal (
 
-  -- * Compression and decompression
-  compressDefault,
-  decompressDefault,
-  Stream.BlockSize(..),
+  -- * Compression
+  compress,
+  CompressParams(..),
+  defaultCompressParams,
 
-  -- * The same but with the full set of parameters
-  compressFull,
-  decompressFull,
+  -- * Decompression
+  decompress,
+  DecompressParams(..),
+  defaultDecompressParams,
+
+  -- * The compression parameter types
+  Stream.BlockSize(..),
   Stream.WorkFactor(..),
   Stream.MemoryLevel(..),
-  Stream.Verbosity(..),
-
   ) where
 
 import Prelude hiding (length)
@@ -40,55 +43,102 @@
 import qualified Codec.Compression.BZip.Stream as Stream
 import Codec.Compression.BZip.Stream (Stream)
 
-compressDefault
-  :: Stream.BlockSize
-  -> L.ByteString
-  -> L.ByteString
-compressDefault blockSize =
-  compressFull blockSize
-               Stream.Silent
-               Stream.DefaultWorkFactor
+-- | The full set of parameters for compression. The defaults are
+-- 'defaultCompressParams'.
+--
+-- The 'compressBufferSize' is the size of the first output buffer containing
+-- the compressed data. If you know an approximate upper bound on the size of
+-- the compressed data then setting this parameter can save memory. The default
+-- compression output buffer size is @16k@. If your extimate is wrong it does
+-- not matter too much, the default buffer size will be used for the remaining
+-- chunks.
+--
+data CompressParams = CompressParams {
+  compressBlockSize   :: Stream.BlockSize,
+  compressWorkFactor  :: Stream.WorkFactor,
+  compressBufferSize  :: Int
+}
 
-decompressDefault
-  :: L.ByteString
-  -> L.ByteString
-decompressDefault =
-  decompressFull Stream.Silent
-                 Stream.DefaultMemoryLevel
+-- | The full set of parameters for decompression. The defaults are
+-- 'defaultDecompressParams'.
+--
+-- The 'decompressBufferSize' is the size of the first output buffer,
+-- containing the uncompressed data. If you know an exact or approximate upper
+-- bound on the size of the decompressed data then setting this parameter can
+-- save memory. The default decompression output buffer size is @32k@. If your
+-- extimate is wrong it does not matter too much, the default buffer size will
+-- be used for the remaining chunks.
+--
+-- One particular use case for setting the 'decompressBufferSize' is if you
+-- know the exact size of the decompressed data and want to produce a strict
+-- 'Data.ByteString.ByteString'. The compression and deccompression functions
+-- use lazy 'Data.ByteString.Lazy.ByteString's but if you set the
+-- 'decompressBufferSize' correctly then you can generate a lazy
+-- 'Data.ByteString.Lazy.ByteString' with exactly one chunk, which can be
+-- converted to a strict 'Data.ByteString.ByteString' in @O(1)@ time using
+-- @'Data.ByteString.concat' . 'Data.ByteString.Lazy.toChunks'@.
+--
+data DecompressParams = DecompressParams {
+  decompressMemoryLevel :: Stream.MemoryLevel,
+  decompressBufferSize  :: Int
+}
 
-{-# NOINLINE compressFull #-}
-compressFull
-  :: Stream.BlockSize
-  -> Stream.Verbosity
-  -> Stream.WorkFactor
+-- | The default set of parameters for compression. This is typically used with
+-- the @compressWith@ function with specific paramaters overridden.
+--
+defaultCompressParams :: CompressParams
+defaultCompressParams = CompressParams {
+  compressBlockSize   = Stream.DefaultBlockSize,
+  compressWorkFactor  = Stream.DefaultWorkFactor,
+  compressBufferSize  = defaultCompressBufferSize
+}
+
+-- | The default set of parameters for decompression. This is typically used with
+-- the @compressWith@ function with specific paramaters overridden.
+--
+defaultDecompressParams :: DecompressParams
+defaultDecompressParams = DecompressParams {
+  decompressMemoryLevel = Stream.DefaultMemoryLevel,
+  decompressBufferSize  = defaultDecompressBufferSize
+}
+
+-- | The default chunk sizes for the output of compression and decompression
+-- are 16k and 32k respectively (less a small accounting overhead).
+--
+defaultCompressBufferSize, defaultDecompressBufferSize :: Int
+#ifdef BYTESTRING_IN_BASE
+defaultCompressBufferSize   = 16 * 1024 - 16
+defaultDecompressBufferSize = 32 * 1024 - 16
+#else
+defaultCompressBufferSize   = 16 * 1024 - L.chunkOverhead
+defaultDecompressBufferSize = 32 * 1024 - L.chunkOverhead
+#endif
+
+{-# NOINLINE compress #-}
+compress
+  :: CompressParams
   -> L.ByteString
   -> L.ByteString
-compressFull blockSize verbosity workFactor input =
+compress (CompressParams blockSize workFactor initChunkSize) input =
   L.fromChunks $ Stream.run $ do
-    Stream.compressInit blockSize verbosity workFactor
+    Stream.compressInit blockSize Stream.Silent workFactor
     case L.toChunks input of
-      [] -> fillBuffers []
+      [] -> fillBuffers 14 [] --bzip2 header is 14 bytes
       S.PS inFPtr offset length : chunks -> do
         Stream.pushInputBuffer inFPtr offset length
-        fillBuffers chunks
+        fillBuffers initChunkSize chunks
 
   where
-#ifdef BYTESTRING_IN_BASE
-  outChunkSize = 16 * 1024 - 16
-#else
-  outChunkSize = 32 * 1024 - L.chunkOverhead
-#endif
-
     -- we flick between two states:
     --   * where one or other buffer is empty
     --       - in which case we refill one or both
     --   * where both buffers are non-empty
     --       - in which case we compress until a buffer is empty
 
-  fillBuffers ::
-      [S.ByteString]
-   -> Stream [S.ByteString]
-  fillBuffers inChunks = do
+  fillBuffers :: Int
+              -> [S.ByteString]
+              -> Stream [S.ByteString]
+  fillBuffers outChunkSize inChunks = do
     Stream.consistencyCheck
 
     -- in this state there are two possabilities:
@@ -133,9 +183,10 @@
         outputBufferFull <- Stream.outputBufferFull
         if outputBufferFull
           then do (outFPtr, offset, length) <- Stream.popOutputBuffer
-                  outChunks <- Stream.unsafeInterleave (fillBuffers inChunks)
+                  outChunks <- Stream.unsafeInterleave
+                    (fillBuffers defaultCompressBufferSize inChunks)
                   return (S.PS outFPtr offset length : outChunks)
-          else do fillBuffers inChunks
+          else do fillBuffers defaultCompressBufferSize inChunks
 
       Stream.StreamEnd -> do
         inputBufferEmpty <- Stream.inputBufferEmpty
@@ -149,39 +200,31 @@
                   return []
 
 
-{-# NOINLINE decompressFull #-}
-decompressFull
-  :: Stream.Verbosity
-  -> Stream.MemoryLevel
+{-# NOINLINE decompress #-}
+decompress
+  :: DecompressParams
   -> L.ByteString
   -> L.ByteString
-decompressFull verbosity memLevel input =
+decompress (DecompressParams memLevel initChunkSize) input =
   L.fromChunks $ Stream.run $ do
-    Stream.decompressInit verbosity memLevel
+    Stream.decompressInit Stream.Silent memLevel
     case L.toChunks input of
-      [] -> fillBuffers []
+      [] -> fillBuffers 4 [] --always an error anyway
       S.PS inFPtr offset length : chunks -> do
         Stream.pushInputBuffer inFPtr offset length
-        fillBuffers chunks
+        fillBuffers initChunkSize chunks
 
   where
-  outChunkSize :: Int
-#ifdef BYTESTRING_IN_BASE
-  outChunkSize = 16 * 1024 - 16
-#else
-  outChunkSize = 32 * 1024 - L.chunkOverhead
-#endif
-
     -- we flick between two states:
     --   * where one or other buffer is empty
     --       - in which case we refill one or both
     --   * where both buffers are non-empty
     --       - in which case we compress until a buffer is empty
 
-  fillBuffers ::
-      [S.ByteString]
-   -> Stream [S.ByteString]
-  fillBuffers inChunks = do
+  fillBuffers :: Int
+              -> [S.ByteString]
+              -> Stream [S.ByteString]
+  fillBuffers outChunkSize inChunks = do
 
     -- in this state there are two possabilities:
     --   * no outbut buffer space is available
@@ -225,13 +268,14 @@
         outputBufferFull <- Stream.outputBufferFull
         if outputBufferFull
           then do (outFPtr, offset, length) <- Stream.popOutputBuffer
-                  outChunks <- Stream.unsafeInterleave (fillBuffers inChunks)
+                  outChunks <- Stream.unsafeInterleave
+                    (fillBuffers defaultDecompressBufferSize inChunks)
                   return (S.PS outFPtr offset length : outChunks)
           else do -- We need to detect if we ran out of input:
                   inputBufferEmpty <- Stream.inputBufferEmpty
                   if inputBufferEmpty && null inChunks
                     then fail "premature end of compressed stream"
-                    else fillBuffers inChunks
+                    else fillBuffers defaultDecompressBufferSize inChunks
 
       Stream.StreamEnd -> do
         -- Note that there may be input bytes still available if the stream
diff --git a/Codec/Compression/BZip/Stream.hsc b/Codec/Compression/BZip/Stream.hsc
--- a/Codec/Compression/BZip/Stream.hsc
+++ b/Codec/Compression/BZip/Stream.hsc
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -fno-warn-missing-methods #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
 -----------------------------------------------------------------------------
 -- |
 -- Copyright   :  (c) 2006-2008 Duncan Coutts
@@ -56,11 +56,16 @@
   ) where
 
 import Foreign
+         ( Word8, Ptr, nullPtr, plusPtr, peekByteOff, pokeByteOff, mallocBytes
+         , ForeignPtr, FinalizerPtr, newForeignPtr_, addForeignPtrFinalizer
+         , finalizeForeignPtr, withForeignPtr, touchForeignPtr
+         , unsafeForeignPtrToPtr, unsafePerformIO )
 import Foreign.C
+         ( CInt, CUInt )
 #ifdef BYTESTRING_IN_BASE
-import Data.ByteString.Base
+import Data.ByteString.Base (nullForeignPtr)
 #else
-import Data.ByteString.Internal
+import Data.ByteString.Internal (nullForeignPtr)
 #endif
 import System.IO.Unsafe (unsafeInterleaveIO)
 import System.IO (hPutStrLn, stderr)
@@ -363,13 +368,13 @@
   | StreamEnd  -- ^ Compression of data was completed, or the logical stream
                --   end was detected during decompression.
 
-instance Enum Status where
-  toEnum (#{const BZ_OK})         = Ok
-  toEnum (#{const BZ_RUN_OK})     = Ok
-  toEnum (#{const BZ_FLUSH_OK})   = Ok
-  toEnum (#{const BZ_FINISH_OK})  = Ok
-  toEnum (#{const BZ_STREAM_END}) = StreamEnd
-  toEnum other = error ("unexpected bzip2 status: " ++ show other)
+toStatus :: CInt -> Status
+toStatus (#{const BZ_OK})         = Ok
+toStatus (#{const BZ_RUN_OK})     = Ok
+toStatus (#{const BZ_FLUSH_OK})   = Ok
+toStatus (#{const BZ_FINISH_OK})  = Ok
+toStatus (#{const BZ_STREAM_END}) = StreamEnd
+toStatus other = error ("unexpected bzip2 status: " ++ show other)
 
 failIfError :: CInt -> Stream ()
 failIfError errno
@@ -392,10 +397,10 @@
   | Flush
   | Finish
 
-instance Enum Action where
-  fromEnum Run    = #{const BZ_RUN}
-  fromEnum Flush  = #{const BZ_FLUSH}
-  fromEnum Finish = #{const BZ_FINISH}
+fromAction :: Action -> CInt
+fromAction Run    = #{const BZ_RUN}
+fromAction Flush  = #{const BZ_FLUSH}
+fromAction Finish = #{const BZ_FINISH}
 
 -- | The block size affects both the compression ratio achieved, and the amount
 -- of memory needed for compression and decompression.
@@ -429,11 +434,11 @@
     DefaultBlockSize -- ^ The default block size is also the maximum.
   | BlockSize Int    -- ^ A specific block size between 1 and 9.
 
-instance Enum BlockSize where
-  fromEnum DefaultBlockSize = 9
-  fromEnum (BlockSize n)
-         | n >= 1 && n <= 9 = n
-         | otherwise        = error "BlockSize must be in the range 1..9"
+fromBlockSize :: BlockSize -> CInt
+fromBlockSize DefaultBlockSize = 9
+fromBlockSize (BlockSize n)
+            | n >= 1 && n <= 9 = fromIntegral n
+            | otherwise        = error "BlockSize must be in the range 1..9"
 
 -- | For files compressed with the default 900k block size, decompression will
 -- require about 3700k to decompress. To support decompression of any file in
@@ -447,9 +452,9 @@
                        --   halves the memory needed but also halves the
                        --   decompression speed.
 
-instance Enum MemoryLevel where
-  fromEnum DefaultMemoryLevel = 0
-  fromEnum MinMemoryLevel     = 1
+fromMemoryLevel :: MemoryLevel -> CInt
+fromMemoryLevel DefaultMemoryLevel = 0
+fromMemoryLevel MinMemoryLevel     = 1
 
 -- | The 'WorkFactor' parameter controls how the compression phase behaves when
 -- presented with worst case, highly repetitive, input data. If compression
@@ -472,11 +477,11 @@
     DefaultWorkFactor -- ^ The default work factor is 30.
   | WorkFactor Int    -- ^ Allowable values range from 1 to 250 inclusive.
 
-instance Enum WorkFactor where
-  fromEnum DefaultWorkFactor = 0
-  fromEnum (WorkFactor n)
-        | n >= 1 && n <= 250 = n
-        | otherwise          = error "WorkFactor must be in the range 1..250"
+fromWorkFactor :: WorkFactor -> CInt
+fromWorkFactor DefaultWorkFactor = 0
+fromWorkFactor (WorkFactor n)
+      | n >= 1 && n <= 250 = fromIntegral n
+      | otherwise          = error "WorkFactor must be in the range 1..250"
 
 -- | The 'Verbosity' parameter is a number between 0 and 4. 0 is silent, and
 -- greater numbers give increasingly verbose monitoring\/debugging output.
@@ -484,11 +489,11 @@
 data Verbosity = Silent        -- ^ No output. This is the default.
                | Verbosity Int -- ^ A specific level between 0 and 4.
 
-instance Enum Verbosity where
-  fromEnum Silent = 0
-  fromEnum (Verbosity n)
-      | n >= 0 && n <= 4 = n
-      | otherwise        = error "Verbosity must be in the range 0..4"
+fromVerbosity :: Verbosity -> CInt
+fromVerbosity Silent        = 0
+fromVerbosity (Verbosity n)
+         | n >= 0 && n <= 4 = fromIntegral n
+         | otherwise        = error "Verbosity must be in the range 0..4"
 
 withStreamPtr :: (Ptr StreamState -> IO a) -> Stream a
 withStreamPtr f = do
@@ -532,8 +537,8 @@
 decompressInit verbosity memoryLevel = do
   err <- withStreamState $ \bzstream ->
     bzDecompressInit bzstream
-      (fromIntegral (fromEnum verbosity))
-      (fromIntegral (fromEnum memoryLevel))
+      (fromVerbosity verbosity)
+      (fromMemoryLevel memoryLevel)
   failIfError err
   getStreamState >>= unsafeLiftIO . addForeignPtrFinalizer bzDecompressEnd
 
@@ -541,9 +546,9 @@
 compressInit blockSize verbosity workFactor = do
   err <- withStreamState $ \bzstream ->
     bzCompressInit bzstream
-      (fromIntegral (fromEnum blockSize))
-      (fromIntegral (fromEnum verbosity))
-      (fromIntegral (fromEnum workFactor))
+      (fromBlockSize blockSize)
+      (fromVerbosity verbosity)
+      (fromWorkFactor workFactor)
   failIfError err
   getStreamState >>= unsafeLiftIO . addForeignPtrFinalizer bzCompressEnd
 
@@ -552,14 +557,14 @@
   err <- withStreamState $ \bzstream ->
     bzDecompress bzstream
   failIfError err
-  return (toEnum (fromIntegral err))
+  return (toStatus err)
 
 compress_ :: Action -> Stream Status
 compress_ action = do
   err <- withStreamState $ \bzstream ->
-    bzCompress bzstream (fromIntegral (fromEnum action))
+    bzCompress bzstream (fromAction action)
   failIfError err
-  return (toEnum (fromIntegral err))
+  return (toStatus err)
 
 -- | This never needs to be used as the stream's resources will be released
 -- automatically when no longer needed, however this can be used to release
diff --git a/bzlib.cabal b/bzlib.cabal
--- a/bzlib.cabal
+++ b/bzlib.cabal
@@ -1,5 +1,5 @@
 name:            bzlib
-version:         0.4.0.3
+version:         0.5.0.0
 copyright:       (c) 2006-2008 Duncan Coutts
 license:         BSD3
 license-file:    LICENSE
@@ -44,7 +44,7 @@
     extra-libraries: bz2
   else
     -- However for the benefit of users of Windows (which does not have zlib
-    -- by default) we bundle a complete copy of the C sources of bzip2-1.0.4
+    -- by default) we bundle a complete copy of the C sources of bzip2-1.0.5
     c-sources:     cbits/blocksort.c cbits/bzlib.c cbits/compress.c
                    cbits/crctable.c cbits/decompress.c cbits/huffman.c
                    cbits/randtable.c
diff --git a/cbits/blocksort.c b/cbits/blocksort.c
--- a/cbits/blocksort.c
+++ b/cbits/blocksort.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/bzlib.c b/cbits/bzlib.c
--- a/cbits/bzlib.c
+++ b/cbits/bzlib.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
@@ -48,7 +48,7 @@
       "component, you should also report this bug to the author(s)\n"
       "of that program.  Please make an effort to report this bug;\n"
       "timely and accurate bug reports eventually lead to higher\n"
-      "quality software.  Thanks.  Julian Seward, 15 February 2005.\n\n",
+      "quality software.  Thanks.  Julian Seward, 10 December 2007.\n\n",
       errcode,
       BZ2_bzlibVersion()
    );
@@ -598,6 +598,7 @@
       UInt32        c_tPos               = s->tPos;
       char*         cs_next_out          = s->strm->next_out;
       unsigned int  cs_avail_out         = s->strm->avail_out;
+      Int32         ro_blockSize100k     = s->blockSize100k;
       /* end restore */
 
       UInt32       avail_out_INIT = cs_avail_out;
diff --git a/cbits/bzlib.h b/cbits/bzlib.h
--- a/cbits/bzlib.h
+++ b/cbits/bzlib.h
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/bzlib_private.h b/cbits/bzlib_private.h
--- a/cbits/bzlib_private.h
+++ b/cbits/bzlib_private.h
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
@@ -36,7 +36,7 @@
 
 /*-- General stuff. --*/
 
-#define BZ_VERSION  "1.0.4, 20-Dec-2006"
+#define BZ_VERSION  "1.0.5, 10-Dec-2007"
 
 typedef char            Char;
 typedef unsigned char   Bool;
@@ -442,11 +442,15 @@
 /*-- Macros for decompression. --*/
 
 #define BZ_GET_FAST(cccc)                     \
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
     s->tPos = s->tt[s->tPos];                 \
     cccc = (UChar)(s->tPos & 0xff);           \
     s->tPos >>= 8;
 
 #define BZ_GET_FAST_C(cccc)                   \
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
     c_tPos = c_tt[c_tPos];                    \
     cccc = (UChar)(c_tPos & 0xff);            \
     c_tPos >>= 8;
@@ -469,8 +473,10 @@
    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
 
 #define BZ_GET_SMALL(cccc)                            \
-      cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
-      s->tPos = GET_LL(s->tPos);
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
+    cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
+    s->tPos = GET_LL(s->tPos);
 
 
 /*-- externs for decompression. --*/
diff --git a/cbits/compress.c b/cbits/compress.c
--- a/cbits/compress.c
+++ b/cbits/compress.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/crctable.c b/cbits/crctable.c
--- a/cbits/crctable.c
+++ b/cbits/crctable.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/decompress.c b/cbits/decompress.c
--- a/cbits/decompress.c
+++ b/cbits/decompress.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/huffman.c b/cbits/huffman.c
--- a/cbits/huffman.c
+++ b/cbits/huffman.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
diff --git a/cbits/randtable.c b/cbits/randtable.c
--- a/cbits/randtable.c
+++ b/cbits/randtable.c
@@ -8,8 +8,8 @@
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.5 of 10 December 2007
+   Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
