[llvm] [Object][DirectX] Fix UB when parsing a DXContainer from a null buffer (PR #200865)
Ilia Kuklin via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 09:49:18 PDT 2026
https://github.com/kuilpd created https://github.com/llvm/llvm-project/pull/200865
Adds an additional check that `Src != nullptr` before doing other operations on it, which caused a UB in one test with #200413.
>From 7ca6c3af24b3afc8f1db383911fb92d77d9bc8c6 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Mon, 1 Jun 2026 21:33:10 +0500
Subject: [PATCH] [Object][DX] Fix UB when parsing a DXContainer from a null
buffer
---
llvm/lib/Object/DXContainer.cpp | 2 +-
llvm/unittests/Object/DXContainerTest.cpp | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 0ca2fc6de3857..6d50ff7edcd30 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -21,7 +21,7 @@ static Error parseFailed(const Twine &Msg) {
}
static bool readIsOutOfBounds(StringRef Buffer, const char *Src, size_t Size) {
- return Src < Buffer.begin() || Src + Size > Buffer.end();
+ return !Src || Src < Buffer.begin() || Src + Size > Buffer.end();
}
template <typename T>
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 1526e1a380672..4eb81e0a0ed3a 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -50,6 +50,12 @@ TEST(DXCFile, EmptyFile) {
FailedWithMessage("Reading structure out of file bounds"));
}
+TEST(DXCFile, NullBuffer) {
+ EXPECT_THAT_EXPECTED(
+ DXContainer::create(MemoryBufferRef(StringRef(), "")),
+ FailedWithMessage("Reading structure out of file bounds"));
+}
+
TEST(DXCFile, ParseHeader) {
uint8_t Buffer[] = {0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
More information about the llvm-commits
mailing list