From: Sean Purcell Date: Tue, 16 May 2017 14:00:51 +0000 (-0400) Subject: Fix zstd memory allocation and null checks X-Git-Tag: v3.3.3~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bc18e0e8eadc83685c7407b29768ee96f26b227;p=thirdparty%2Flibarchive.git Fix zstd memory allocation and null checks --- diff --git a/libarchive/archive_read_support_filter_zstd.c b/libarchive/archive_read_support_filter_zstd.c index f8a759068..c8bb36be7 100644 --- a/libarchive/archive_read_support_filter_zstd.c +++ b/libarchive/archive_read_support_filter_zstd.c @@ -165,28 +165,29 @@ zstd_bidder_init(struct archive_read_filter *self) struct private_data *state; const size_t out_block_size = ZSTD_DStreamOutSize(); void *out_block; + ZSTD_DStream *dstream; self->code = ARCHIVE_FILTER_ZSTD; self->name = "zstd"; state = (struct private_data *)calloc(sizeof(*state), 1); out_block = (unsigned char *)malloc(out_block_size); + dstream = ZSTD_createDStream(); - self->data = state; - - state->dstream = ZSTD_createDStream(); - - if (state == NULL || out_block == NULL || state->dstream == NULL) { + if (state == NULL || out_block == NULL || dstream == NULL) { free(out_block); free(state); - ZSTD_freeDStream(state->dstream); /* supports free on NULL */ + ZSTD_freeDStream(dstream); /* supports free on NULL */ archive_set_error(&self->archive->archive, ENOMEM, "Can't allocate data for zstd decompression"); return (ARCHIVE_FATAL); } + self->data = state; + state->out_block_size = out_block_size; state->out_block = out_block; + state->dstream = dstream; self->read = zstd_filter_read; self->skip = NULL; /* not supported */ self->close = zstd_filter_close;