Handle null blocks correctly in mkzftree -u
diff --git a/mkzftree.c b/mkzftree.c
index 14579f0..47d5489 100644
--- a/mkzftree.c
+++ b/mkzftree.c
@@ -284,26 +284,31 @@
csize = cend-cstart;
- if ( csize > block_size2 ) {
- errno = EINVAL;
- goto free_ptr_bail;
+ if ( csize == 0 ) {
+ memset(outbuf, 0, block_size);
+ bytes = block_size;
+ } else {
+ if ( csize > block_size2 ) {
+ errno = EINVAL;
+ goto free_ptr_bail;
+ }
+
+ if ( fseek(input, cstart, SEEK_SET) == -1 )
+ goto free_ptr_bail;
+
+ errno = 0;
+ if ( (bytes = fread(inbuf, 1, csize, input)) != csize ) {
+ if ( errno == 0 ) errno = EINVAL;
+ goto free_ptr_bail;
+ }
+
+ bytes = block_size; /* Max output buffer size */
+ if ( (zerr = uncompress(outbuf, &bytes, inbuf, csize)) != Z_OK ) {
+ errno = (zerr = Z_MEM_ERROR) ? ENOMEM : EINVAL;
+ goto free_ptr_bail;
+ }
}
-
- if ( fseek(input, cstart, SEEK_SET) == -1 )
- goto free_ptr_bail;
-
- errno = 0;
- if ( (bytes = fread(inbuf, 1, csize, input)) != csize ) {
- if ( errno == 0 ) errno = EINVAL;
- goto free_ptr_bail;
- }
-
- bytes = block_size; /* Max output buffer size */
- if ( (zerr = uncompress(outbuf, &bytes, inbuf, csize)) != Z_OK ) {
- errno = (zerr = Z_MEM_ERROR) ? ENOMEM : EINVAL;
- goto free_ptr_bail;
- }
-
+
if ( ((fullsize > block_size) && (bytes != block_size))
|| ((fullsize <= block_size) && (bytes < fullsize)) ) {
errno = EINVAL;