Skip to content

[mlir] Reject dense_resource blobs with zero alignment#181350

Open
Ayush3941 wants to merge 2 commits into
llvm:mainfrom
Ayush3941:out-of-memory
Open

[mlir] Reject dense_resource blobs with zero alignment#181350
Ayush3941 wants to merge 2 commits into
llvm:mainfrom
Ayush3941:out-of-memory

Conversation

@Ayush3941
Copy link
Copy Markdown
Contributor

@Ayush3941 Ayush3941 commented Feb 13, 2026

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

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Feb 13, 2026
@llvmbot llvmbot temporarily deployed to main-branch-only February 13, 2026 12:10 — with GitHub Actions Inactive
@llvmbot llvmbot temporarily deployed to main-branch-only February 13, 2026 12:10 — with GitHub Actions Inactive
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 13, 2026

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Ayush Kumar Gaur (Ayush3941)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/181350.diff

2 Files Affected:

  • (modified) mlir/lib/AsmParser/Parser.cpp (+1-1)
  • (added) mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir (+12)
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"
+    }
+  }
+#-}

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 13, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLVM ERROR: out of memory

2 participants