mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Try to avoid fatal filter failures by better scanning during the setup phase.
This commit is contained in:
parent
a37a75aecc
commit
dde49f0bb4
|
@ -58,10 +58,18 @@ static int F(Filter *f)
|
|||
// must not conflict with the mark.
|
||||
// Note that unsigned comparison checks both edges of buffer.
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
|
@ -79,8 +87,7 @@ static int F(Filter *f)
|
|||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
|
|
|
@ -57,10 +57,18 @@ static int F(Filter *f)
|
|||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic,lastcall))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
|
@ -78,8 +86,7 @@ static int F(Filter *f)
|
|||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
|
|
|
@ -58,10 +58,18 @@ static int F(Filter *f)
|
|||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall,id) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic,lastcall,id))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
|
@ -79,8 +87,7 @@ static int F(Filter *f)
|
|||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
|
|
|
@ -109,7 +109,7 @@ umin(unsigned const a, unsigned const b)
|
|||
|
||||
#define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define COND2(b,x,lc) (lc!=(x) && 0xf==b[(x)-1] && 0x80<=b[x] && b[x]<=0x8f)
|
||||
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
|
||||
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
|
||||
#define F f_ctok32_e8e9_bswap_le
|
||||
#define U u_ctok32_e8e9_bswap_le
|
||||
#include "filter/ctok.h"
|
||||
|
|
Loading…
Reference in New Issue
Block a user