Software Security

Table of Contents

Integer overflows

Ints have a fixed size.

For x86-64 Linux:

typebitsminmax
signed char8$-2^{7}$$2^{7}-1$
unsigned char80$2^{8}-1$
short16$-2^{15}$$2^{15}-1$
unsigned short160$2^{16}-1$
int32$-2^{31}$$2^{31}-1$
unsigned int320$2^{32}-1$
long64$-2^{63}$$2^{63}-1$
unsigned long640$2^{64}-1$

If number doesn’t fit, overflow. CPU discards bits that don’t fit. i.e. result is computed modulo 2ⁿ (n = number of bits).

leads to unexpected results in casts, computation, comparison: