diff --git a/src/compress.cpp b/src/compress.cpp index a5ce6666..ee5e0d51 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -149,6 +149,9 @@ int upx_decompress ( const upx_bytep src, upx_uint src_len, { int r = UPX_E_ERROR; + assert(*dst_len > 0); + assert(src_len < *dst_len); // must be compressed + if (result && result->method == 0) result = NULL; @@ -188,6 +191,7 @@ int upx_test_overlap ( const upx_bytep buf, upx_uint src_off, if (result && result->method == 0) result = NULL; + assert(*dst_len > 0); assert(src_len < *dst_len); // must be compressed unsigned overlap_overhead = src_off + src_len - *dst_len; assert((int)overlap_overhead > 0); diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index aed1b15e..6505ca78 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -319,23 +319,24 @@ PackLinuxElf32x86::buildLinuxLoader( unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc]; if (0 < szfold) { - memset(cprLoader, 0, sizeof(h) + h.sz_unc); h.sz_cpr = h.sz_unc; // amount that the compressor may use int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h.sz_cpr, NULL, ph.method, 10, NULL, NULL ); if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc) throwInternalError("loader compression failed"); +#if 1 //{ if (M_LZMA==ph.method) { // FIXME: debugging only ucl_uint tmp_len = h.sz_unc; // LZMA uses this as EOF - unsigned char *tmp = new unsigned char[h.sz_unc]; - memset(tmp, 0, h.sz_unc); + unsigned char *tmp = new unsigned char[tmp_len]; + memset(tmp, 0, tmp_len); r = upx_decompress(sizeof(h) + cprLoader, h.sz_cpr, tmp, &tmp_len, h.b_method, NULL); - printf("%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len); + printf("\n%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len); for (unsigned j=0; j < h.sz_unc; ++j) if (tmp[j]!=uncLoader[j]) { printf("%d: %x %x\n", j, tmp[j], uncLoader[j]); } delete[] tmp; } +#endif //} } memcpy(cprLoader, &h, sizeof(h));