[mlir] Reject dense_resource blobs with zero alignment#181350
Open
Ayush3941 wants to merge 2 commits into
Open
[mlir] Reject dense_resource blobs with zero alignment#181350Ayush3941 wants to merge 2 commits into
Ayush3941 wants to merge 2 commits into
Conversation
Member
|
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Ayush Kumar Gaur (Ayush3941) ChangesWhat's the problemmlir-opt could abort with “LLVM ERROR: out of memory” when parsing dense_resource blobs whose first 4 bytes encode alignment=0. Why it happenedThe parser allowed alignment=0 due to a missing validation check, leading to invalid allocator calls. Whats the FixReject alignment=0 (and non-power-of-2 values) with a proper diagnostic and add a regression test. Full diff: https://github.com/llvm/llvm-project/pull/181350.diff 2 Files Affected:
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 22928df03fbc7..f53cfec377bf6 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -2699,7 +2699,7 @@ class ParsedResourceEntry : public AsmParsedResourceEntry {
}
llvm::support::ulittle32_t align;
memcpy(&align, blobData->data(), sizeof(uint32_t));
- if (align && !llvm::isPowerOf2_32(align)) {
+ if (align==0 || !llvm::isPowerOf2_32(align)) {
return p.emitError(value.getLoc(),
"expected hex string blob for key '" + key +
"' to encode alignment in first 4 bytes, but got "
diff --git a/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir b/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir
new file mode 100644
index 0000000000000..3d1f22089b83d
--- /dev/null
+++ b/mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt -allow-unregistered-dialect %s -verify-diagnostics
+
+"test.user_op"() {attr = dense_resource<double_data> : tensor<2xf64>} : () -> ()
+
+{-#
+ dialect_resources: {
+ builtin: {
+ // expected-error @+1 {{expected hex string blob for key 'double_data' to encode alignment in first 4 bytes, but got non-power-of-2 value: 0}}
+ double_data: "0x000000000000F03F0000000000000040"
+ }
+ }
+#-}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem
mlir-opt could abort with “LLVM ERROR: out of memory” when parsing dense_resource blobs whose first 4 bytes encode alignment=0.
Why it happened
The parser allowed alignment=0 due to a missing validation check, leading to invalid allocator calls.
Whats the Fix
Reject alignment=0 (and non-power-of-2 values) with a proper diagnostic and add a regression test.
Fixes #181266