kaitai_struct
kaitai_struct copied to clipboard
`_sizeof` special property does not properly handle conditional fields
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.
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