Fix Dispack decoding.

This commit is contained in:
Moinak Ghosh 2013-11-24 22:44:35 +05:30
parent 0192790c02
commit 4923551570
2 changed files with 18 additions and 15 deletions

View file

@ -1041,16 +1041,19 @@ dispack_decode(uchar_t *from, uint64_t fromlen, uchar_t *to, uint64_t *dstlen)
} }
if (type & DISFILTERED) { if (type & DISFILTERED) {
if (pos_to + sz > to_last) if (pos_to + sz > to_last) {
return (-1); return (-1);
if (DisUnFilter(pos, cmpsz, pos_to, sz, 0) != sTRUE) }
if (DisUnFilter(pos, cmpsz, pos_to, sz, 0) != sTRUE) {
return (-1); return (-1);
}
pos += cmpsz; pos += cmpsz;
pos_to += sz; pos_to += sz;
len -= cmpsz; len -= cmpsz;
} else { } else {
if (pos_to + cmpsz > to_last) if (pos_to + cmpsz > to_last) {
return (-1); return (-1);
}
memcpy(pos_to, pos, cmpsz); memcpy(pos_to, pos, cmpsz);
pos += cmpsz; pos += cmpsz;
pos_to += cmpsz; pos_to += cmpsz;

View file

@ -308,7 +308,7 @@ preproc_decompress(pc_ctx_t *pctx, compress_func_ptr dec_func, void *src, uint64
{ {
uchar_t *sorc = (uchar_t *)src, type; uchar_t *sorc = (uchar_t *)src, type;
int64_t result; int64_t result;
uint64_t _dstlen = *dstlen; uint64_t _dstlen = *dstlen, _dstlen1 = *dstlen;
DEBUG_STAT_EN(double strt, en); DEBUG_STAT_EN(double strt, en);
type = *sorc; type = *sorc;
@ -337,6 +337,7 @@ preproc_decompress(pc_ctx_t *pctx, compress_func_ptr dec_func, void *src, uint64
srclen = _dstlen; srclen = _dstlen;
*dstlen = _dstlen; *dstlen = _dstlen;
} else { } else {
log_msg(LOG_ERR, 0, "Delta2 decoding failed.");
return (result); return (result);
} }
} }
@ -346,24 +347,23 @@ preproc_decompress(pc_ctx_t *pctx, compress_func_ptr dec_func, void *src, uint64
hashsize = lzp_hash_size(level); hashsize = lzp_hash_size(level);
result = lzp_decompress((const uchar_t *)src, (uchar_t *)dst, srclen, result = lzp_decompress((const uchar_t *)src, (uchar_t *)dst, srclen,
hashsize, LZP_DEFAULT_LZPMINLEN, 0); hashsize, LZP_DEFAULT_LZPMINLEN, 0);
if (result < 0) { if (result > 0) {
memcpy(src, dst, result);
srclen = result;
*dstlen = result;
_dstlen = result;
} else {
log_msg(LOG_ERR, 0, "LZP decompression failed."); log_msg(LOG_ERR, 0, "LZP decompression failed.");
return (-1); return (result);
} }
*dstlen = result;
} }
/*
* If Dispack is enabled it has to be done first since Dispack analyses the
* x86 instruction stream in the raw data.
*/
if (type & PREPROC_TYPE_DISPACK) { if (type & PREPROC_TYPE_DISPACK) {
result = dispack_decode((uchar_t *)src, srclen, (uchar_t *)dst, &_dstlen); result = dispack_decode((uchar_t *)src, srclen, (uchar_t *)dst, &_dstlen1);
if (result != -1) { if (result != -1) {
memcpy(src, dst, _dstlen); *dstlen = _dstlen1;
srclen = _dstlen;
*dstlen = _dstlen;
} else { } else {
log_msg(LOG_ERR, 0, "Dispack decoding failed.");
return (result); return (result);
} }
} }