relinker: x86 decoder returns a length 2 bytes short for 0x66 + REX.W instructions with an imm32 #1162
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oguzhanozfe on 2026-10-07T15:52:34Z.
X64InstructionDecoder::Decodesizes the immediate as imm16 whenever the 0x66 operand-size prefix is present, even when REX.W is also present. In 64-bit mode REX.W takes precedence over 0x66 (Intel SDM Vol. 1 §3.6.1, Table 3-4; Vol. 2A §2.2.1.2), so the operand size is 64 bits and the immediate stays imm32.The
B8+rcase already applies this rule (core/relinker/codegen/src/x86/X64InstructionDecoder.cpp:175, covered by66 48 B8 imm64indecoderLengths). The other imm32 opcodes at line 178 and theF7 /0TEST form at line 282 do not.Decode66 48 81 C0 imm3266 48 05 imm3266 48 C7 C0 imm3266 48 69 C0 imm3266 48 68 imm3266 48 A9 imm3266 48 F7 C0 imm32DecodeInstructiontakes its length fromDecode, so it is wrong too.InstructionScannersweeps linearly, so the bytes after the short length are decoded as the next instruction and the rest of the sweep is out of step with the real instruction stream.Controls that are decoded correctly:
66 81 C0 iw(5),48 66 81 C0 iw(REX not directly before the opcode is ignored, 6),66 41 81 C0 iw(REX without W, 6),66 48 B8 imm64(11).Reproduced by compiling the current
X64InstructionDecoder.cpp(main at4e742835) with MSVC 14.50 and callingDecodeon each sequence followed by eight 0x90 bytes.