[BusyBox-cvs] busybox/archival/libunarchive decompress_bunzip2.c, 1.7, 1.8

Glenn McGrath bug1 at busybox.net
Tue Oct 28 23:32:15 UTC 2003


Update of /var/cvs/busybox/archival/libunarchive
In directory winder:/tmp/cvs-serv12727/archival/libunarchive

Modified Files:
	decompress_bunzip2.c 
Log Message:
Add some error messages, use xmalloc instead of malloc


Index: decompress_bunzip2.c
===================================================================
RCS file: /var/cvs/busybox/archival/libunarchive/decompress_bunzip2.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- decompress_bunzip2.c	23 Oct 2003 06:52:01 -0000	1.7
+++ decompress_bunzip2.c	28 Oct 2003 23:32:12 -0000	1.8
@@ -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 @@
 	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 @@
 	   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 @@
 	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 @@
 		}
 	}
 	/* 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;
 }
 




More information about the busybox-cvs mailing list