[llvm] [X86][Disassembler] Reject instructions longer than 15 bytes (PR #208277)
Charles Zablit via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 06:15:42 PDT 2026
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/208277
>From be40fd8c63d41b891d5bd391ebc435c34306047d Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 8 Jul 2026 18:49:49 +0100
Subject: [PATCH 1/3] [X86][Disassembler] Reject instructions longer than 15
bytes
---
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
index d499dc43dcab6..1d83ee40b9bc1 100644
--- a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -1835,8 +1835,10 @@ MCDisassembler::DecodeStatus X86GenericDisassembler::getInstruction(
Insn.operands = x86OperandSets[Insn.spec->operands];
Insn.length = Insn.readerCursor - Insn.startLocation;
Size = Insn.length;
- if (Size > 15)
+ if (Size > 15) {
LLVM_DEBUG(dbgs() << "Instruction exceeds 15-byte limit");
+ return Fail;
+ }
bool Ret = translateInstruction(Instr, Insn, this);
if (!Ret) {
>From f2efdfb0b49be49b2f7bc566831d72ba728f95b6 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 8 Jul 2026 20:11:00 +0100
Subject: [PATCH 2/3] add test
---
.../Disassembler/X86/x86-64-instruction-length.txt | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
diff --git a/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt b/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
new file mode 100644
index 0000000000000..20fcd5af4a5d3
--- /dev/null
+++ b/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
@@ -0,0 +1,14 @@
+# RUN: rm -rf %t && split-file %s %t
+# RUN: llvm-mc --disassemble %t/at-limit.txt -triple=x86_64 2>&1 | FileCheck %s --check-prefix=LIMIT --implicit-check-not=warning:
+# RUN: llvm-mc --disassemble %t/too-long.txt -triple=x86_64 2>&1 | FileCheck %s --check-prefix=TOOLONG --implicit-check-not=nop
+
+#--- at-limit.txt
+## 14 redundant operand-size (0x66) prefixes + NOP = 15 bytes: exactly the
+## limit.
+0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x90
+# LIMIT: nop
+
+#--- too-long.txt
+## One more prefix (16 bytes): too long.
+0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x90
+# TOOLONG: warning: invalid instruction encoding
\ No newline at end of file
>From 86e309919662ccf4dff4f6872e28b39fffcb0282 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 9 Jul 2026 14:15:30 +0100
Subject: [PATCH 3/3] fixup! add test
---
.../X86/x86-64-instruction-length.txt | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt b/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
index 20fcd5af4a5d3..cd441eca022c0 100644
--- a/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
+++ b/llvm/test/MC/Disassembler/X86/x86-64-instruction-length.txt
@@ -1,14 +1,5 @@
-# RUN: rm -rf %t && split-file %s %t
-# RUN: llvm-mc --disassemble %t/at-limit.txt -triple=x86_64 2>&1 | FileCheck %s --check-prefix=LIMIT --implicit-check-not=warning:
-# RUN: llvm-mc --disassemble %t/too-long.txt -triple=x86_64 2>&1 | FileCheck %s --check-prefix=TOOLONG --implicit-check-not=nop
+# RUN: llvm-mc --disassemble %s -triple=x86_64 2>&1 | FileCheck %s
-#--- at-limit.txt
-## 14 redundant operand-size (0x66) prefixes + NOP = 15 bytes: exactly the
-## limit.
-0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x90
-# LIMIT: nop
-
-#--- too-long.txt
-## One more prefix (16 bytes): too long.
+## 15 redundant operand-size (0x66) prefixes + NOP = 16 bytes, over the limit.
+# CHECK: warning: invalid instruction encoding
0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x90
-# TOOLONG: warning: invalid instruction encoding
\ No newline at end of file
More information about the llvm-commits
mailing list