[all-commits] [llvm/llvm-project] 781719: [ASan][Windows] Fix false positive for zero sized ...
Zack Johnson via All-commits
all-commits at lists.llvm.org
Fri Feb 13 12:49:49 PST 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 781719778003ca298ca57e486ab629b7f384844b
https://github.com/llvm/llvm-project/commit/781719778003ca298ca57e486ab629b7f384844b
Author: Zack Johnson <zacklj89 at gmail.com>
Date: 2026-02-13 (Fri, 13 Feb 2026)
Changed paths:
M compiler-rt/lib/asan/asan_allocator.cpp
M compiler-rt/lib/asan/asan_malloc_win.cpp
M compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp
A compiler-rt/test/asan/TestCases/Windows/rtlsizeheap_zero.cpp
Log Message:
-----------
[ASan][Windows] Fix false positive for zero sized rtl allocations (#181015)
This is a follow up to #155943
On Windows, ASan's allocator internally upgrades zero-size allocation
requests to size 1 (since malloc(0) must return a unique non-NULL
pointer). However, when the user queries the allocation size through
Windows heap APIs (RtlSizeHeap, HeapSize, \_msize, GlobalSize,
LocalSize), ASan reports the internal size (1) instead of the originally
requested size (0).
This causes false positive heap-buffer-overflow errors in a common
pattern:
```c++
void *buf = HeapAlloc(GetProcessHeap(), 0, 0);
SIZE_T size = HeapSize(GetProcessHeap(), 0, buf); // Returns 1, should be 0
if(size > 0) // could remove this and still be correct
memset(buf, 0, size); // ASan reports heap-buffer-overflow
```
The change adds a `from_zero_alloc` bit to `ChunkHeader` that tracks
whether an allocation was originally zero-size. This bit fits in the
existing spare capacity of the header's bitfield byte, so the 16-byte
ChunkHeader size is unchanged, but it also isn't the most elegant.
The 1-byte user region of a zero-size allocation is still poisoned, so
any actual access to it is correctly reported as an overflow.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list