aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/BinaryFormat/DXContainer.cpp
diff options
context:
space:
mode:
authorjoaosaffran <joaosaffranllvm@gmail.com>2025-10-06 14:21:28 -0700
committerGitHub <noreply@github.com>2025-10-06 17:21:28 -0400
commit58ce3e20e55c67298da94eabe4e25f8baeb45fa7 (patch)
treec53883f31e83293c4e13556e8a1b3779f3f9ca52 /llvm/lib/BinaryFormat/DXContainer.cpp
parent74af5784a570914271a258618bf6f7cb06c50241 (diff)
downloadllvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.zip
llvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.tar.gz
llvm-58ce3e20e55c67298da94eabe4e25f8baeb45fa7.tar.bz2
[DirectX] Fix Flags validation to prevent casting into enum (#161587)
This PR changes the validation logic for Root Descriptor and Descriptor Range flags to properly check if the `uint32_t` values are within range before casting into the enums.
Diffstat (limited to 'llvm/lib/BinaryFormat/DXContainer.cpp')
-rw-r--r--llvm/lib/BinaryFormat/DXContainer.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/BinaryFormat/DXContainer.cpp b/llvm/lib/BinaryFormat/DXContainer.cpp
index b334f86..22f5180 100644
--- a/llvm/lib/BinaryFormat/DXContainer.cpp
+++ b/llvm/lib/BinaryFormat/DXContainer.cpp
@@ -82,6 +82,27 @@ bool llvm::dxbc::isValidBorderColor(uint32_t V) {
return false;
}
+bool llvm::dxbc::isValidRootDesciptorFlags(uint32_t V) {
+ using FlagT = dxbc::RootDescriptorFlags;
+ uint32_t LargestValue =
+ llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
+ return V < NextPowerOf2(LargestValue);
+}
+
+bool llvm::dxbc::isValidDescriptorRangeFlags(uint32_t V) {
+ using FlagT = dxbc::DescriptorRangeFlags;
+ uint32_t LargestValue =
+ llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
+ return V < NextPowerOf2(LargestValue);
+}
+
+bool llvm::dxbc::isValidStaticSamplerFlags(uint32_t V) {
+ using FlagT = dxbc::StaticSamplerFlags;
+ uint32_t LargestValue =
+ llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
+ return V < NextPowerOf2(LargestValue);
+}
+
dxbc::PartType dxbc::parsePartType(StringRef S) {
#define CONTAINER_PART(PartName) .Case(#PartName, PartType::PartName)
return StringSwitch<dxbc::PartType>(S)