mirror of
https://github.com/upx/upx
synced 2025-10-05 19:20:23 +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.
|
// must not conflict with the mark.
|
||||||
// Note that unsigned comparison checks both edges of buffer.
|
// Note that unsigned comparison checks both edges of buffer.
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
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)
|
if (getcto(f, buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -79,8 +87,7 @@ static int F(Filter *f)
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
return 1; // fail - buffer not restored
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,10 +57,18 @@ static int F(Filter *f)
|
||||||
memset(buf,0,256);
|
memset(buf,0,256);
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
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)
|
if (getcto(f, buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -78,8 +86,7 @@ static int F(Filter *f)
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
return 1; // fail - buffer not restored
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,10 +58,18 @@ static int F(Filter *f)
|
||||||
memset(buf,0,256);
|
memset(buf,0,256);
|
||||||
|
|
||||||
for (ic = 0; ic < size - 5; ic++)
|
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)
|
if (getcto(f, buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -79,8 +87,7 @@ static int F(Filter *f)
|
||||||
// try to detect 'real' calls only
|
// try to detect 'real' calls only
|
||||||
if (jc < size)
|
if (jc < size)
|
||||||
{
|
{
|
||||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||||
return 1; // fail - buffer not restored
|
|
||||||
#ifdef U
|
#ifdef U
|
||||||
set_be32(b+ic+1,jc+addvalue+cto);
|
set_be32(b+ic+1,jc+addvalue+cto);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -109,7 +109,7 @@ umin(unsigned const a, unsigned const b)
|
||||||
|
|
||||||
#define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
#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 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 F f_ctok32_e8e9_bswap_le
|
||||||
#define U u_ctok32_e8e9_bswap_le
|
#define U u_ctok32_e8e9_bswap_le
|
||||||
#include "filter/ctok.h"
|
#include "filter/ctok.h"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user