Skip to content

Decoder can be initialized with ill-formed defaults #237

@mappzor

Description

@mappzor

ZydisDecoderInit accepts machine_mode and address_width. In conjunction those arguments will determine decoder's default values for stack size (ssz), operand size (osz) and address size (asz). Typically Zydis users pass matching values (e.g. 32-bit machine mode with 32-bit address width) but decoder logic acts improperly when those values do not match:
(decoder->machine_mode, decoder->address_width) -> (ssz, osz, asz)
(16, 32) -> (32, 16, 32)
(32, 16) -> (16, 32, 16)

Such defaults are not possible on real hardware. They are controlled by D/B flag in CS and SS. For CS we have CS.D that controls "effective addresses and operands referenced by instructions in the segment", so default values of osz and asz, should be always the same. For SS we have SS.B that determines ssz.

Expected behavior would be to derive osz and asz from machine_mode and take ssz from address_width (which probably should be named stack_width just as in decoded instruction).

Metadata

Metadata

Assignees

Labels

A-decoderArea: DecoderC-bugCategory: This is a bug (or a fix for a bug, when applied to PRs)P-mediumPriority: Medium

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions