hackweb
notes on hacking and technology
IT EN
main menu
user menu
you are not logged in

Integer overflow: when numbers wrap

October 5, 2025 · 1 min read · #binary-exploitation #integer-overflow #memory

Integers have finite size. uint32 at 0xFFFFFFFF + 1 wraps to 0. If a size or index overflows, checks are bypassed.

int len = a + b;          // a+b overflows -> len small/negative
char *p = malloc(len);    // too-small buffer
memcpy(p, src, a + b);    // but the copy uses the real value -> overflow

Variants: signed/unsigned confusion (a negative becomes huge in size_t), multiplication overflow (count * size), truncation going 64 to 32 bits.

Defence

Safe-arithmetic checks: verify a > MAX - b before adding, use overflow-checking allocators (calloc, reallocarray), consistent types (size_t), and sanitizers (-fsanitize=integer) in testing.


« back to home

latest posts
 
your IP address:
216.73.216.108
visitor #0
MOTD:
Every abstraction leaks somewhere.
Here we look at where.
topics