diff options
author | Glenn L McGrath | 2003-10-28 23:32:12 +0000 |
---|---|---|
committer | Glenn L McGrath | 2003-10-28 23:32:12 +0000 |
commit | 1c834407e39197d9d3f127d4783b75af5e793319 (patch) | |
tree | d9f20d07ff6021edefac50b83ed8719a00031143 /archival | |
parent | debb21ece7be5a17b468bab0cba74f8026008d0d (diff) | |
download | busybox-1c834407e39197d9d3f127d4783b75af5e793319.zip busybox-1c834407e39197d9d3f127d4783b75af5e793319.tar.gz |
Add some error messages, use xmalloc instead of malloc
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index f00c439..83232fb 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c @@ -47,6 +47,8 @@ #include <unistd.h> #include <limits.h> +#include "libbb.h" + /* Constants for huffman coding */ #define MAX_GROUPS 6 #define GROUP_SIZE 50 /* 64 would have been more efficient */ @@ -520,7 +522,7 @@ extern int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len) i=sizeof(bunzip_data); if(in_fd!=-1) i+=IOBUF_SIZE; /* Allocate bunzip_data. Most fields initialize to zero. */ - if(!(bd=*bdp=malloc(i))) return RETVAL_OUT_OF_MEMORY; + bd=*bdp=xmalloc(i); memset(bd,0,sizeof(bunzip_data)); /* Setup input buffer */ if(-1==(bd->in_fd=in_fd)) { @@ -546,8 +548,7 @@ extern int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len) uncompressed data. Allocate intermediate buffer for block. */ bd->dbufSize=100000*(i-BZh0); - if(!(bd->dbuf=malloc(bd->dbufSize * sizeof(int)))) - return RETVAL_OUT_OF_MEMORY; + bd->dbuf=xmalloc(bd->dbufSize * sizeof(int)); return RETVAL_OK; } @@ -559,7 +560,7 @@ extern int uncompressStream(int src_fd, int dst_fd) bunzip_data *bd; int i; - if(!(outbuf=malloc(IOBUF_SIZE))) return RETVAL_OUT_OF_MEMORY; + outbuf=xmalloc(IOBUF_SIZE); if(!(i=start_bunzip(&bd,src_fd,0,0))) { for(;;) { if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; @@ -570,10 +571,22 @@ extern int uncompressStream(int src_fd, int dst_fd) } } /* Check CRC and release memory */ - if(i==RETVAL_LAST_BLOCK && bd->headerCRC==bd->totalCRC) i=RETVAL_OK; + if(i==RETVAL_LAST_BLOCK) { + if (bd->headerCRC!=bd->totalCRC) { + bb_error_msg("Data integrity error when decompressing."); + } else { + i=RETVAL_OK; + } + } + else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { + bb_error_msg("Compressed file ends unexpectedly"); + } else { + bb_error_msg("Decompression failed"); + } if(bd->dbuf) free(bd->dbuf); free(bd); free(outbuf); + return i; } |