diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-09-02 19:33:32 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-09-02 19:33:32 +0300 |
commit | 9c75b089b4a9e0edcf4cf7970a4383768707d6c8 (patch) | |
tree | 15294dffa1d99f1c20d02a23953010d298781124 | |
parent | Auto decoder cleanup (diff) | |
download | xz-9c75b089b4a9e0edcf4cf7970a4383768707d6c8.tar.xz |
Command line tool fixes
-rw-r--r-- | src/lzma/process.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/lzma/process.c b/src/lzma/process.c index b4387709..42c625e3 100644 --- a/src/lzma/process.c +++ b/src/lzma/process.c @@ -194,6 +194,7 @@ single(thread_data *t) uint8_t in_buf[BUFSIZ]; uint8_t out_buf[BUFSIZ]; lzma_action action = LZMA_RUN; + lzma_ret ret; bool success = false; t->strm.avail_in = 0; @@ -212,7 +213,7 @@ single(thread_data *t) action = LZMA_FINISH; } - const lzma_ret ret = lzma_code(&t->strm, action); + ret = lzma_code(&t->strm, action); if ((t->strm.avail_out == 0 || ret != LZMA_OK) && opt_mode != MODE_TEST) { @@ -225,17 +226,21 @@ single(thread_data *t) } if (ret != LZMA_OK) { - if (ret == LZMA_STREAM_END) { - // FIXME !!! This doesn't work when decoding - // LZMA_Alone files, because LZMA_Alone decoder - // doesn't wait for LZMA_FINISH. - assert(t->pair->src_eof); - success = true; - } else { + // Check that there is no trailing garbage. This is + // needed for LZMA_Alone and raw streams. + if (ret == LZMA_STREAM_END && (t->strm.avail_in != 0 + || (!t->pair->src_eof && io_read( + t->pair, in_buf, 1) != 0))) + ret = LZMA_DATA_ERROR; + + if (ret != LZMA_STREAM_END) { errmsg(V_ERROR, "%s: %s", t->pair->src_name, str_strm_error(ret)); + break; } + assert(t->pair->src_eof); + success = true; break; } } |