aboutsummaryrefslogtreecommitdiff
path: root/unpack
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-04 15:32:52 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-04 22:22:48 +0200
commit2b975a449c17268f943403176a7609079b7af084 (patch)
treefee51e2f4b4f424c9a55dc35fb7aad21e3ce6580 /unpack
parent6f7ee71165b30272a4f18bca361c324c7671680c (diff)
Remove compressor internal buffers
Pass in an external destination buffer + size and allow for propper bounds checking (especially when unpacking). Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack')
-rw-r--r--unpack/extract_file.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/unpack/extract_file.c b/unpack/extract_file.c
index c18ace8..368f6d7 100644
--- a/unpack/extract_file.c
+++ b/unpack/extract_file.c
@@ -4,18 +4,19 @@
int extract_file(file_info_t *fi, compressor_t *cmp, size_t block_size,
frag_reader_t *frag, int sqfsfd, int outfd)
{
+ void *buffer, *scratch, *ptr;
size_t i, count, fragsz;
bool compressed;
- void *buffer;
uint32_t bs;
ssize_t ret;
- buffer = malloc(block_size);
+ buffer = malloc(block_size * 2);
if (buffer == NULL) {
perror("allocating scratch buffer");
return -1;
}
+ scratch = (char *)buffer + block_size;
count = fi->size / block_size;
if (count > 0) {
@@ -39,14 +40,18 @@ int extract_file(file_info_t *fi, compressor_t *cmp, size_t block_size,
goto fail_trunc;
if (compressed) {
- ret = cmp->do_block(cmp, buffer, bs);
+ ret = cmp->do_block(cmp, buffer, bs,
+ scratch, block_size);
if (ret <= 0)
goto fail;
bs = ret;
+ ptr = scratch;
+ } else {
+ ptr = buffer;
}
- ret = write_retry(outfd, buffer, bs);
+ ret = write_retry(outfd, ptr, bs);
if (ret < 0)
goto fail_wr;