Skip to content

Commit c3a47f5

Browse files
authored
Merge pull request #52 from colinlove/fix/legacy-alias-path-no-terminator
fix(elements): accept legacy alias paths without trailing null terminator
2 parents 298d271 + 1cb4218 commit c3a47f5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎acd/l5x/elements.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,13 @@ def _legacy_data_type(self, record: LegacyRxGeneric) -> str:
19321932
return atomic_types.get(record.main_record.runtime_type & 0xFF, "")
19331933

19341934
def _legacy_alias_for(self, value: bytes) -> str:
1935-
if len(value) % 2 or not value.endswith(b"\x00\x00"):
1935+
# Usually null-terminated (a trailing b"\x00\x00" utf-16 code unit),
1936+
# but observed on real project files without one -- a path ending in
1937+
# a literal ".<member/bit>" reference (e.g. an alias into a bit or an
1938+
# array/structure member) can occupy the field's full length with no
1939+
# terminator at all. The length just needs to be a whole number of
1940+
# utf-16 code units; a missing terminator isn't itself invalid.
1941+
if len(value) % 2:
19361942
raise ValueError("Invalid legacy alias path")
19371943
path = value.decode("utf-16-le").rstrip("\x00")
19381944

0 commit comments

Comments
 (0)