mirror of
https://github.com/upx/upx.git
synced 2024-11-23 20:59:55 +00:00
Added throwOutOfMemoryException().
This commit is contained in:
parent
cb2ff92c2f
commit
40e19293f9
@ -161,6 +161,14 @@ void throwBadLoader()
|
||||
}
|
||||
|
||||
|
||||
void throwOutOfMemoryException(const char *msg)
|
||||
{
|
||||
if (msg == NULL)
|
||||
msg = "out of memory";
|
||||
throw OutOfMemoryException(msg);
|
||||
}
|
||||
|
||||
|
||||
void throwIOException(const char *msg, int e)
|
||||
{
|
||||
throw IOException(msg, e);
|
||||
|
@ -220,6 +220,7 @@ void throwBadLoader() NORET;
|
||||
void throwChecksumError() NORET;
|
||||
void throwCompressedDataViolation() NORET;
|
||||
void throwInternalError(const char *msg) NORET;
|
||||
void throwOutOfMemoryException(const char *msg = NULL) NORET;
|
||||
void throwIOException(const char *msg = NULL, int e = 0) NORET;
|
||||
void throwEOFException(const char *msg = NULL, int e = 0) NORET;
|
||||
|
||||
|
@ -159,7 +159,9 @@ void ElfLinker::init(const void *pdata_v, int plen)
|
||||
input = new upx_byte[inputlen + 1];
|
||||
unsigned new_len = u_len;
|
||||
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL);
|
||||
if (r != 0 || new_len != u_len)
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || new_len != u_len)
|
||||
throwBadLoader();
|
||||
}
|
||||
else
|
||||
|
@ -192,11 +192,7 @@ void MemBuffer::alloc(unsigned size)
|
||||
assert((int)total > 0);
|
||||
unsigned char *p = (unsigned char *) malloc(total);
|
||||
if (!p)
|
||||
{
|
||||
//throw bad_alloc();
|
||||
throw OutOfMemoryException("out of memory");
|
||||
//exit(1);
|
||||
}
|
||||
throwOutOfMemoryException();
|
||||
b_size = size;
|
||||
if (use_mcheck)
|
||||
{
|
||||
|
@ -481,6 +481,8 @@ PackLinuxElf32::buildLinuxLoader(
|
||||
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);
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
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]);
|
||||
|
@ -194,6 +194,8 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
|
||||
unsigned sz_bh = SZ_IH_BKUP;
|
||||
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
|
||||
unc_bh, &sz_bh, M_NRV2E_8, NULL );
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
|
||||
throwInternalError("header decompression failed");
|
||||
unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP);
|
||||
|
@ -245,7 +245,7 @@ bool Packer::compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
|
||||
uip->endCallback();
|
||||
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwCantPack("out of memory");
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK)
|
||||
throwInternalError("compression failed");
|
||||
|
||||
@ -282,6 +282,8 @@ bool Packer::compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
|
||||
// decompress
|
||||
unsigned new_len = ph.u_len;
|
||||
r = upx_decompress(o_ptr, ph.c_len, i_ptr, &new_len, ph.method, &ph.compress_result);
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
//printf("%d %d: %d %d %d\n", ph.method, r, ph.c_len, ph.u_len, new_len);
|
||||
if (r != UPX_E_OK)
|
||||
throwInternalError("decompression failed");
|
||||
@ -360,6 +362,8 @@ void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
|
||||
// decompress
|
||||
unsigned new_len = ph.u_len;
|
||||
int r = upx_decompress(in, ph.c_len, out, &new_len, ph.method, &ph.compress_result);
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || new_len != ph.u_len)
|
||||
throwCompressedDataViolation();
|
||||
|
||||
@ -412,6 +416,8 @@ bool ph_testOverlappingDecompression(const PackHeader &ph,
|
||||
int r = upx_test_overlap(buf - src_off, tbuf,
|
||||
src_off, ph.c_len, &new_len,
|
||||
ph.method, &ph.compress_result);
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
return (r == UPX_E_OK && new_len == ph.u_len);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user