(MSVC) Address sanitizer reporting heap courrption in example apps (windows and simple)

I was thinking of filing this as a bug, but I wanted to try posting here first and see if there’s something I’m missing. I was working with raylib, which uses GLFW, when I started getting heap corruption errors from address sanitizer. It happened after I updated visual studio, so I’m not sure if this is an issue with MSVC or GLFW. I cloned GLFW’s current master branch, and discovered the same behavior on it (just running the example apps), ruling out raylib and my project’s code as the culprit.

Observed issue:

Address sanitizer detects heap corruption when initializing window. This only occurs when I run an example (unmodified except to enable address sanitizer) with the screen attached to my Nvidia card. Does NOT occur when running with only the laptop screen (Intel).

Here’s a video of it, sorry about potato quality. Works on laptop display only (Intel), breaks when Nvidia gets involved.

Repo steps:

On Windows 11, use the current version of visual studio (17.2.6), ensure you have address sanitizer installed.

Clone glfw (master or tags/3.3.7)

In examples/CmakeLists.txt, under the if (MSVC) block add:
target_compile_options(windows PRIVATE /Zi /fsanitize=address)
or if you’re testing against tags/3.3.7
target_compile_options(simple PRIVATE /Zi /fsanitize=address)

Select windows (master) or simple (tags/3.3.7) and run.

System

Visual Studio 17.2.6
Nvidia driver 516.59
Intel driver 101.1994
(Note I used Display Driver Uninstaller to remove all my display drivers and install latest versions fresh, problem persisted)
Windows 11 - 21H2 - build 22000.795

This looks similar, heap corruption at the same GDI call. Just old AMD driver and different lib. Possibly this issue is Nvidia driver bug for version 516.59, would explain why it seemed to happen out of no where. I’ll see if I can roll back a driver version…

Tried a driver version from January (511), no change. Going to try different MSVC build tools.
Rolled back to 17.0.11, which 100% worked before, and now getting the same issue.
Going to try rolling back Nvidia further, possibly intel driver too.
Tried rolling back both drivers to older versions, did not help

Can you right click on call stack entries with ntdll.dll and select “Load symbols”? And then check if one of functions there is with LocalSize or GlobalSize name?

If yes, then this is probably older bug in address sanitizer where it did not hook into those functions correctly. I don’t know if they have fixed in later MSVC versions (try upgrading to latest vs2022), but for older MSVC you could fix it by setting ASAN_OPTIONS=windows_hook_legacy_allocators=true environment option for your program.