Fix bug#1011.
authorWerner Koch <wk@gnupg.org>
Thu, 3 Sep 2009 11:29:25 +0000 (11:29 +0000)
committerWerner Koch <wk@gnupg.org>
Thu, 3 Sep 2009 11:29:25 +0000 (11:29 +0000)
g10/ChangeLog
g10/compress-bz2.c

index 120b32f..9d77b7d 100644 (file)
@@ -1,3 +1,8 @@
+2009-09-03  Werner Koch  <wk@g10code.com>
+
+       * compress-bz2.c (do_uncompress): Detect unexpected EOF.  Fix
+       bug#1011.
+
 2009-08-26  Werner Koch  <wk@g10code.com>
 
        * keyedit.c (menu_revsig): Check for signature right away.  Fix
 
        * keygen.c (ask_key_flags): Fix bug in the translation check.
        Fixes bug#1056.
-       
+
 2009-05-18  Daiki Ueno  <ueno@unixuser.org>  (wk)
 
        * encode.c (encode_simple): Tell passphrase_to_dek to cache
 
        * gpg.c (reopen_std): Moved to ../common and renamed to
        gnupg_reopen_std.
-       
+
        * gpg.c: Remove second inclusion of fcntl.h.
 
 2007-11-19  Werner Koch  <wk@g10code.com>
        alias to it.  --rfc2440 now stands alone.  For now, use the old
        2440 defaults for 4880.
        * misc.c (compliance_option_string): Ditto.
-       
+
        * keyedit.c (keyedit_menu): Use compliance_option_string() instead
        of printing the compliance modes here.
 
 2007-10-25  David Shaw  <dshaw@jabberwocky.com>  (wk)
 
        From 1.4 (July):
-       
+
        * armor.c (parse_header_line): Improve test so that the header
        test only allows "Hash" in the signed data section.
 
        * gpg.c, gpgv.c: Include sysutils.h.
        (main): Replace iobuf_translate_file_handle by
        translate_sys2libc_fd.
-       
 
 2007-06-21  Werner Koch  <wk@g10code.com>
 
 
        * misc.c (setsysinfo, trap_unaligned): Remove.  It is also in
        common/sysutils.c.
-       (disable_core_dumps, get_session_marker): 
+       (disable_core_dumps, get_session_marker):
 
        * sign.c (sleep): Remove sleep wrapper.
 
index 3c1c649..1dabca1 100644 (file)
@@ -118,6 +118,7 @@ do_uncompress( compress_filter_context_t *zfx, bz_stream *bzs,
   size_t n;
   int nread, count;
   int refill = !bzs->avail_in;
+  int eofseen = 0;
 
   if( DBG_FILTER )
     log_debug("begin bzDecompress: avail_in=%u, avail_out=%u, inbuf=%u\n",
@@ -132,12 +133,16 @@ do_uncompress( compress_filter_context_t *zfx, bz_stream *bzs,
            bzs->next_in = zfx->inbuf;
          count = zfx->inbufsize - n;
          nread = iobuf_read( a, zfx->inbuf + n, count );
-         if( nread == -1 ) nread = 0;
+         if( nread == -1 )
+            {
+              eofseen = 1;
+              nread = 0;
+            }
          n += nread;
          bzs->avail_in = n;
        }
-
-      refill = 1;
+      if (!eofseen)
+        refill = 1;
 
       if( DBG_FILTER )
        log_debug("enter bzDecompress: avail_in=%u, avail_out=%u\n",
@@ -151,6 +156,13 @@ do_uncompress( compress_filter_context_t *zfx, bz_stream *bzs,
        rc = -1; /* eof */
       else if( zrc != BZ_OK && zrc != BZ_PARAM_ERROR )
        log_fatal("bz2lib inflate problem: rc=%d\n", zrc );
+      else if (zrc == BZ_OK && eofseen 
+               && !bzs->avail_in && bzs->avail_out > 0)
+        {
+          log_error ("unexpected EOF in bz2lib\n");
+          rc = GPG_ERR_BAD_DATA;
+          break;
+        }
     }
   while( bzs->avail_out && zrc != BZ_STREAM_END && zrc != BZ_PARAM_ERROR );