kaitai_struct icon indicating copy to clipboard operation
kaitai_struct copied to clipboard

`_sizeof` special property does not properly handle conditional fields

Open Mingun opened this issue 2 years ago • 1 comments

The following KSY successfully compiles although _sizeof expression depends on the presence of the value field which is dependent on the _sizeof result.

meta:
  id: sizeof_bug
seq:
  - id: value
    size: 2
    if: _sizeof == 1
    # or this:
    # if: _root._sizeof == 1

(_sizeof calculated as 2) Compiler should detect this situation and raise an error.

Mingun avatar Nov 21 '21 17:11 Mingun

A bug in those lines: size calculations does not consider an if key: https://github.com/kaitai-io/kaitai_struct_compiler/blob/e8542816277c0f78a17afcd4eed756337df9cd70/shared/src/main/scala/io/kaitai/struct/precompile/CalculateSeqSizes.scala#L63-L77

Mingun avatar Nov 25 '21 16:11 Mingun