1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Better underflow and overflow handling in Packer::findOverlapOverhead().

This commit is contained in:
Markus F.X.J. Oberhumer 2007-04-26 13:59:01 +02:00
parent 5f203fc082
commit c96e8a8c19

View File

@ -501,13 +501,15 @@ unsigned Packer::findOverlapOverhead(const upx_bytep buf,
// Succeed early if m lies in [low .. low+range-1], i.e. if
// if the range of the current interval is <= range.
// if (m <= low + range - 1)
if (m + 1 <= low + range) // avoid underflow
// if (m < low + range)
if (m - low < range) // avoid underflow
break;
high = m - 1;
}
else
low = m + 1;
m = (low + high) / 2;
////m = (low + high) / 2;
m = (low & high) + ((low ^ high) >> 1); // avoid overflow
}
//printf("findOverlapOverhead: %d (%d tries)\n", overhead, nr);