Skip to content

fix(elements): accept legacy alias paths without trailing null terminator - #52

Merged
hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/legacy-alias-path-no-terminator
Nov 3, 2026
Merged

hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/legacy-alias-path-no-terminator

Conversation

@colinlove

Copy link
Copy Markdown
Contributor

This fix is part of a series found with AI assistance (Claude Code) — see the first PR in this batch for the full disclosure.


_legacy_alias_for rejects a legacy alias path with no trailing null terminator

Symptom

ValueError: Invalid legacy alias path

aborting the entire export, for a tag whose alias path is well-formed UTF-16
but simply isn't null-terminated.

Root cause

def _legacy_alias_for(self, value: bytes) -> str:
    if len(value) % 2 or not value.endswith(b"\x00\x00"):
        raise ValueError("Invalid legacy alias path")

This assumes a legacy alias path is always terminated with a trailing
b"\x00\x00" UTF-16 code unit. On a real project file, one was found that
is not: 40006100360064003800300065006600630040002e00 decodes as
@a6d80efc@. — a resolved-later object-id placeholder followed by a
literal . with no terminator at all, presumably because the path ends
in a .<member/bit> reference (a bit or array/structure member) that
occupies the field's full stored length with nothing left over for a
terminator.

Fix

Only require the length to be a whole number of UTF-16 code units
(len(value) % 2 == 0); a missing terminator isn't itself invalid. The
existing .rstrip("\x00") on the next line already handles the
terminator's presence correctly, so nothing else needs to change.

Suggested validation

Any legacy alias path ending in a .<member> or .<bit> reference that
happens to consume the field's entire stored length (no trailing null) is
the shape to check for; the fix accepts it while continuing to reject an
odd-length (non-whole-UTF-16) value as before.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hutcheb
hutcheb merged commit c3a47f5 into hutcheb:main Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants