Store the file size as zero when the magic header will be written before the size is known.

This commit is contained in:
Con Kolivas 2011-03-11 23:45:22 +11:00
parent a10d423596
commit d87df4f44e
3 changed files with 6 additions and 2 deletions

View file

@ -57,6 +57,9 @@ void write_magic(rzip_control *control, int fd_in, int fd_out)
if (unlikely(fstat(fd_in, &st)))
fatal("bad magic file descriptor!?\n");
/* File size is stored as zero for streaming STDOUT blocks when the
* file size is unknown. */
if (!STDIN || !STDOUT || control->eof)
memcpy(&magic[6], &control->st_size, 8);
/* save LZMA compression flags */

View file

@ -180,6 +180,7 @@ struct rzip_control {
int encrypt;
i64 secs;
i64 usecs;
int eof;
md5_ctx ctx;
i64 md5_read; // How far into the file the md5 has done so far
};

2
rzip.c
View file

@ -694,7 +694,7 @@ static void mmap_stdin(rzip_control *control, uchar *buf, struct rzip_state *st)
if (unlikely(buf == MAP_FAILED))
fatal("Failed to remap to smaller buf in mmap_stdin\n");
st->mmap_size = st->chunk_size = total;
st->stdin_eof = 1;
control->eof = st->stdin_eof = 1;
break;
}
offset_buf += ret;