Handle oversized blocks

stream
Dave Vasilevsky 12 years ago
parent dd5f6d01e3
commit 3d5d1f1d39

@ -55,6 +55,7 @@ static void tar_write_last(void);
#pragma mark DECLARE READ BUFFER #pragma mark DECLARE READ BUFFER
#define STREAMSIZE (1024 * 1024) #define STREAMSIZE (1024 * 1024)
#define MAXSPLITSIZE (64 * 1024 * 1024) // xz -9 blocksize
static pipeline_item_t *gRbufPI = NULL; static pipeline_item_t *gRbufPI = NULL;
static io_block_t *gRbuf = NULL; static io_block_t *gRbuf = NULL;
@ -71,7 +72,7 @@ static void rbuf_consume(size_t bytes);
static void rbuf_dispatch(void); static void rbuf_dispatch(void);
static bool read_header(lzma_check *check); static bool read_header(lzma_check *check);
static bool read_block(lzma_check check); static bool read_block(bool force_stream, lzma_check check);
static void read_streaming(lzma_block *block); static void read_streaming(lzma_block *block);
static void read_index(void); static void read_index(void);
static void read_footer(void); static void read_footer(void);
@ -328,7 +329,7 @@ static bool read_header(lzma_check *check) {
return true; return true;
} }
static bool read_block(lzma_check check) { static bool read_block(bool force_stream, lzma_check check) {
lzma_filter filters[LZMA_FILTERS_MAX + 1]; lzma_filter filters[LZMA_FILTERS_MAX + 1];
lzma_block block = { .filters = filters, .check = check, .version = 0 }; lzma_block block = { .filters = filters, .check = check, .version = 0 };
@ -346,7 +347,9 @@ static bool read_block(lzma_check check) {
die("Error decoding block header"); die("Error decoding block header");
size_t comp = block.compressed_size, outsize = block.uncompressed_size; size_t comp = block.compressed_size, outsize = block.uncompressed_size;
if (comp == LZMA_VLI_UNKNOWN || outsize == LZMA_VLI_UNKNOWN) { if (force_stream || comp == LZMA_VLI_UNKNOWN
|| outsize == LZMA_VLI_UNKNOWN
|| outsize > MAXSPLITSIZE) {
read_streaming(&block); read_streaming(&block);
} else { } else {
block_capacity(gRbuf, 0, outsize); block_capacity(gRbuf, 0, outsize);
@ -447,7 +450,7 @@ static void read_thread_noindex(void) {
lzma_check check = LZMA_CHECK_NONE; lzma_check check = LZMA_CHECK_NONE;
while (read_header(&check)) { while (read_header(&check)) {
empty = false; empty = false;
while (read_block(check)) while (read_block(false, check))
; // pass ; // pass
read_index(); read_index();
read_footer(); read_footer();
@ -495,6 +498,12 @@ static void read_thread(void) {
fseeko(gInFile, boffset, SEEK_SET); fseeko(gInFile, boffset, SEEK_SET);
offset = boffset; offset = boffset;
} }
if (iter.block.uncompressed_size > MAXSPLITSIZE) { // must stream
if (gRbuf)
rbuf_consume(gRbuf->insize); // clear
read_block(true, iter.stream.flags->check);
} else {
ib->insize = fread(ib->input, 1, bsize, gInFile); ib->insize = fread(ib->input, 1, bsize, gInFile);
if (ib->insize < bsize) if (ib->insize < bsize)
die("Error reading block contents"); die("Error reading block contents");
@ -504,6 +513,7 @@ static void read_thread(void) {
pipeline_split(pi); pipeline_split(pi);
} }
}
pipeline_stop(); pipeline_stop();
} }

Loading…
Cancel
Save