Repository navigation
Open
Description
KSC 0.11-SNAPSHOT at 91aeb53e compiles executable/dex.ksy with the following warnings:
$ kaitai-struct-compiler -- -I . -t python --verbose file executable/dex.ksy
parsing executable/dex.ksy...
reading executable/dex.ksy...
reading ./common/vlq_base128_le.ksy...
... compiling it for python...
.... writing dex.py
.... writing vlq_base128_le.py
executable/dex.ksy: /types/map_list/seq/0/id:
warning: use `num_list` instead of `size`, (...)
executable/dex.ksy: /types/type_list/seq/0/id:
warning: use `num_list` instead of `size`, (...)
executable/dex.ksy: /types/class_def_item/instances/type_name/encoding:
warning: use canonical encoding name `ASCII` instead of `ascii` (see https://doc.kaitai.io/ksy_style_guide.html#encoding-name)
executable/dex.ksy: /types/header_item/seq/1/encoding:
warning: use canonical encoding name `ASCII` instead of `ascii` (see https://doc.kaitai.io/ksy_style_guide.html#encoding-name)The dex.ksy spec has 2 occurrences of encoding:
-
/types/header_item/seq/1/encoding- seeexecutable/dex.ksy:143-151types: header_item: seq: - id: magic contents: "dex\n" - id: version_str size: 4 type: strz encoding: ascii
-
/types/string_id_item/types/string_data_item/seq/1/encoding- seeexecutable/dex.ksy:275-284types: # ... string_id_item: # ... types: string_data_item: -webide-representation: "{data}" seq: - id: utf16_size type: vlq_base128_le - id: data size: utf16_size.value type: str encoding: ascii
As you can see, the warning was correctly reported at /types/header_item/seq/1/encoding, i.e. on the 1st occurrence of encoding in the spec. However, it was not reported on the 2nd occurrence of encoding, i.e. at /types/string_id_item/types/string_data_item/seq/1/encoding.
Instead, it was reported at /types/class_def_item/instances/type_name/encoding:
executable/dex.ksy: /types/class_def_item/instances/type_name/encoding:
warning: use canonical encoding name `ASCII` instead of `ascii` (see https://doc.kaitai.io/ksy_style_guide.html#encoding-name)
But /types/class_def_item/instances/type_name is a value instance that doesn't have the encoding key:
instances:
type_name:
value: _root.type_ids[class_idx].type_name
-webide-parse-mode: eager
Activity
generalmimon commentedon May 3, 2025
The discussion in kaitai-io/kaitai_struct_compiler#278 (comment) is related and hints at the root cause of the problem. Apparently, we're trying to detect non-canonical encoding too late in the compiler's "processing pipeline": on the attribute data types, not in the YAML representation as we should. I believe that
/types/class_def_item/instances/type_nameprobably has the non-canonicalencoding: asciiencoded in its data type (it inherited the same data type as/types/string_id_item/types/string_data_item/seq/1, since it's ultimately just an identity function of it) and that's why the compiler reports the warning on it.generalmimon commentedon May 3, 2025
Another interesting behavior occurs on
filesystem/apm_partition_table.ksy:The problem is that
/types/partition_entrydoesn't have anymeta/encoding, so/types/partition_entryis a fabricated path - see/meta/encodingfilesystem/apm_partition_table.ksy:37-43:Since the only occurrence of
encodinginfilesystem/apm_partition_table.ksyis/meta/encoding, this also means that kaitai-io/kaitai_struct_compiler#278, which was supposed to suppress warnings for inherited encoding like this, doesn't actually work reliably.