[all-commits] [llvm/llvm-project] 85cd3d: Work around documented Linux mmap bug. (#152595)
Richard Smith via All-commits
all-commits at lists.llvm.org
Wed Aug 13 12:39:47 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 85cd3d98686c47d015dbcc17f1f7d0714b00e172
https://github.com/llvm/llvm-project/commit/85cd3d98686c47d015dbcc17f1f7d0714b00e172
Author: Richard Smith <richard at metafoo.co.uk>
Date: 2025-08-13 (Wed, 13 Aug 2025)
Changed paths:
M llvm/lib/Support/MemoryBuffer.cpp
Log Message:
-----------
Work around documented Linux mmap bug. (#152595)
On Linux, mmap doesn't always zero-fill slack bytes ([man page]),
despite being required to do so by POSIX. If the final page of a file is
in the page cache and the bytes past the end of the file get overwritten
by some process, those bytes then remain non-zero until the page falls
out of the cache or another process overwrites them.
Stop trusting that mmap behaves properly and instead check
whether the buffer was indeed properly terminated. If not, fall back to
using `read` to read the file contents.
This fixes an obscure clang crash bug that can occur if another program
(such as an editor) mmap's a source file and writes past the end of the
mmap'd region shortly before clang or clangd attempts to parse the file.
[man page]: https://man7.org/linux/man-pages/man2/mmap.2.html#BUGS
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