Just curious, Is there or has anyone ever come across a heap / buffer overflow exception in C#?
You can cause a buffer overflow in C# in unsafe code. For example:
public unsafe struct testo
{
public int before;
public fixed int items[16];
public int after;
}
testo x = new testo();
x.after = 1;
for (int i = 0; i <= 16; ++i)
{
unsafe
{
x.items[i] = 99;
}
}
Console.WriteLine(x.after);
The above will print "99" because it overflowed the buffer.
Absent unsafe code, I do not know of any way to cause a buffer overrun that doesn't trigger an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With