Fix handling of null StringRef file buffers (#5428)

The current behavior hits UBSAN and ASAN issues.

Note, `RequiresNullTerminator` is already set to `false` in
`source_buffer.cpp`; setting it in `compile_helper.cpp` is making things
more consistent. The related logic is an [assert
fail](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/MemoryBuffer.cpp#L52).

This was fuzzer-discovered.
This commit is contained in:
Jon Ross-Perkins
2025-05-07 22:42:58 +00:00
committed by GitHub
parent 66caff2c26
commit ae16332a11
4 changed files with 38 additions and 8 deletions
+5
View File
@@ -40,6 +40,11 @@ TEST_F(TreeTest, IsValid) {
EXPECT_TRUE((*tree.postorder().begin()).has_value());
}
TEST_F(TreeTest, NullStringRef) {
Tree& tree = compile_helper_.GetTree(llvm::StringRef());
EXPECT_TRUE((*tree.postorder().begin()).has_value());
}
TEST_F(TreeTest, AsAndTryAs) {
auto [tokens, tree_and_subtrees] =
compile_helper_.GetTokenizedBufferWithTreeAndSubtrees("fn F();");