]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Docs: Fix a bug in xz_pipe_decomp.c example program.
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 14 Jun 2012 07:33:01 +0000 (10:33 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 22 Jun 2012 06:31:42 +0000 (09:31 +0300)
doc/examples/xz_pipe_decomp.c

index d4b204d7d5bb78ffd0b7d81d59c14dc2b7e74962..fb5ad89515d736e7ede622605f668ca66694020f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * xz_pipe_decomp.c
  * A simple example of pipe-only xz decompressor implementation.
- * version: 2010-07-12 - by Daniel Mealha Cabrita
+ * version: 2012-06-14 - by Daniel Mealha Cabrita
  * Not copyrighted -- provided to the public domain.
  *
  * Compiling:
@@ -101,6 +101,14 @@ int xz_decompress (FILE *in_file, FILE *out_file)
                } while (strm.avail_out == 0);
        }
 
+       /* Bug fix (2012-06-14): If no errors were detected, check
+          that the last lzma_code() call returned LZMA_STREAM_END.
+          If not, the file is probably truncated. */
+       if ((ret == RET_OK) && (ret_xz != LZMA_STREAM_END)) {
+               fprintf (stderr, "Input truncated or corrupt\n");
+               ret = RET_ERROR_DECOMPRESSION;
+       }
+
        lzma_end (&strm);
        return ret;
 }