Crashes you can’t handle easily #3: STATUS_HEAP_CORRUPTION on Windows

TL;DR: Catching heap corruptions of native heaps is not trivial. Therefore, catching heap corruptions of the C/C++ runtime’s heap is also not trivial.

Heap corruptions are infamously nasty. A few reasons:

  • At times, they might not cause any visible errors at all, making them hard to detect
  • Even if they cause an error, it usually surfaces long after the actual corruption, making them hard to pinpoint
  • Memory that gets corrupted usually has nothing to do with the actual culprit
  • Heap allocations of programs with a GUI are usually not fully deterministic, making a heap corruption potentially hard to reproduce

On Windows, the system can detect a subset of heap corruptions. As with most errors on Windows, this is signaled with an SEH exception. Catching this exception, however, needs some workarounds. But before we get to that, we need to take a look at the architectural relationship between the C/C++ runtime’s heap and native heaps.

Continue reading “Crashes you can’t handle easily #3: STATUS_HEAP_CORRUPTION on Windows”

Crashes you can’t handle easily #2: Stack overflows on Windows

TL;DR: You have to be really careful when handling stack overflows on Windows.

In the previous (and first) entry in this series I wrote about how implementation specifics of x64 SEH can cause you pain if you want to have custom crash reporting. This time I’m going to tell you about the pitfalls of handling stack overflows. “Do you mean some kind of special case of stack overflows?”, you might ask. No, I’m talking about stack overflows in general.

Continue reading “Crashes you can’t handle easily #2: Stack overflows on Windows”

Crashes you can’t handle easily #1: SEH failure on x64 Windows

TL;DR: Don’t expect structured exception handling mechanisms to always work correctly on x64 Windows.

If you ship software, you probably care about crashes. Your product fails and gets terminated, your users get frustrated, their workflow is disrupted, and – worst of all – they might even lose some data. When a crash happens, you want to make sure relevant information is collected and sent back to you, the developer, so the problem can be investigated and fixed.

However, if you don’t rely on your platform’s built-in crash handling facilities, even detecting some crashes is far from trivial. I started this series of blog posts to write about such cases.

Continue reading “Crashes you can’t handle easily #1: SEH failure on x64 Windows”