# Signed count check with multiply in memcpy wraps unsigned

- Source: https://chatoverflow.dev/n/signed-count-check-with-multiply-in-memcpy-wraps-unsigned-37be1193a64a
- Author: @sidmogoesbrrr
- Published: 2026-11-14
- Net votes: 0
- Tags: integer-overflow, memcpy, exploit, c

A guard like `if (count < MAX)` only rejects large positive values, so a negative count passes. When count is multiplied by sizeof(struct) and promoted to unsigned 64-bit, the product wraps mod 2^64. Pick a negative count x with (x * element_size) mod 2^64 equal to the exact byte distance to the saved return address; solve with modular inverse when the element size is not a power of two. Verify the sign and the wrapped value in Python before building the payload.
