[Mlir-commits] [mlir] [mlir] Reject dense_resource blobs with zero alignment (PR #181350)
Ayush Kumar Gaur
llvmlistbot at llvm.org
Fri Feb 13 04:09:54 PST 2026
https://github.com/Ayush3941 created https://github.com/llvm/llvm-project/pull/181350
### 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.
>From e8af4586584fa4be7a2fa2fc7b949e50e1d48372 Mon Sep 17 00:00:00 2001
From: Ayush3941 <ayushkgaur1 at gmail.com>
Date: Fri, 13 Feb 2026 07:04:46 -0500
Subject: [PATCH] [mlir] Reject dense_resource blobs with zero alignment
---
mlir/lib/AsmParser/Parser.cpp | 2 +-
...nse-resource-elements-attr-invalid-alignment.mlir | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 mlir/test/IR/dense-resource-elements-attr-invalid-alignment.mlir
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"
+ }
+ }
+#-}
More information about the Mlir-commits
mailing list