From 4c62e4db6074693175ea1d05b5c12a7d51592e33 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Sat, 29 Nov 2014 13:18:01 +0530 Subject: [PATCH] Fix buffer size handling in metadata chunks. --- meta_stream.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/meta_stream.c b/meta_stream.c index 61f9a78..66c492e 100644 --- a/meta_stream.c +++ b/meta_stream.c @@ -35,7 +35,7 @@ #include #include #include "pcompress.h" -#include "delta2/delta2.h" +#include "filters/delta2/delta2.h" #include "utils/utils.h" #include "lzma/lzma_crc.h" #include "allocator.h" @@ -104,6 +104,7 @@ compress_and_write(meta_ctx_t *mctx) */ tobuf = mctx->tobuf; U64_P(tobuf) = htonll(METADATA_INDICATOR); + U64_P(tobuf + 16) = LE64(mctx->frompos); // Record original length comp_chunk = tobuf + METADATA_HDR_SZ; dstlen = mctx->frompos; @@ -148,7 +149,6 @@ compress_and_write(meta_ctx_t *mctx) * for the header. */ U64_P(tobuf + 8) = LE64(dstlen); - U64_P(tobuf + 16) = LE64(mctx->frompos); *(tobuf + 24) = type; if (!pctx->encrypt_type) @@ -354,13 +354,14 @@ decompress_data(meta_ctx_t *mctx) } if (type & PREPROC_TYPE_DELTA2) { - dstlen = origlen; - rv = delta2_decode(ubuf, len_cmp, cseg, &dstlen); + uint64_t _dstlen = origlen; + rv = delta2_decode(ubuf, dstlen, cseg, &_dstlen); if (rv == -1) { log_msg(LOG_ERR, 0, "Metadata chunk %d, Delta2 decoding failed.", mctx->id); return (0); } - memcpy(ubuf, cseg, dstlen); + memcpy(ubuf, cseg, _dstlen); + dstlen = _dstlen; } /*