Buffer overflow occurs when input data exceeds the allocated buffer size, allowing the program to overwrite adjacent memory. This vulnerability can lead to data corruption or the execution of arbitrary code by an attacker.

The stack manages function calls, local variables, and control flow. When a function is called, the system pushes the return address onto the stack. If this address is overwritten due to a buffer overflow, the instruction pointer can be redirected to malicious code.

Windows and the MSVC compiler utilize a security mechanism known as a stack canary. This value is placed after the buffer to detect unauthorized memory modifications. If the canary is altered, the system triggers a Fail Fast Exception to prevent further exploitation.

Attackers can attempt to bypass the stack canary by including the correct canary sequence within their payload, effectively overwriting the memory while maintaining the expected value.