From 391f5caaa2ecbdfbd4cd2e0c1c2fd1f4c035b85a Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Fri, 23 Jun 2006 05:27:42 +0200 Subject: [PATCH 1/2] Added precondition assertions to upx_decompress(). --- src/compress.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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); From 153446b3a1b77058bb83283e830a7364d576186d Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Fri, 23 Jun 2006 05:40:35 +0200 Subject: [PATCH 2/2] Fixed debugging code. --- src/p_lx_elf.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index caeae18f..67ff9082 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -319,17 +319,20 @@ PackLinuxElf32x86::buildLinuxLoader( unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc]; if (0 < szfold) { + h.sz_cpr = h.sz_unc; 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 = 0; - unsigned char *tmp = new unsigned char[h.sz_unc]; - memset(tmp, 0, h.sz_unc); + upx_uint tmp_len = 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); } +#endif } memcpy(cprLoader, &h, sizeof(h));