Skip to content

fix(elements): guard UDT extended-attribute lookups against absent keys - #51

Merged
hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/udt-missing-extended-attributes
Nov 3, 2026
Merged

hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/udt-missing-extended-attributes

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.


DataTypeBuilder.build() raises KeyError when a UDT lacks certain extended attributes

Symptom

KeyError: 108

raised from:

string_family_int = struct.unpack("<I", extended_records[0x6C])[0]

(0x6C == 108), aborting the entire export. The same bare-dict-lookup
pattern is used two lines later for 0x67 (built_in) and 0x69
(module_defined), which would fail the same way if either were missing
instead.

Root cause

DataTypeBuilder.build() assumes every UDT's extended-record set carries
attributes 0x6C (string-family flag), 0x67 (built-in flag) and 0x69
(module-defined flag). On real project files, plain user-defined types with
no string-family/module-defined role don't always carry these — the code a
few lines below this one already handles exactly this situation correctly
for a different attribute (0x64, member count):

if 0x64 in extended_records and len(extended_records[0x64]) == 0x04:
    member_count = struct.unpack("<I", extended_records[0x64])[0]
else:
    member_count = 0

0x6C/0x67/0x69 just never got the same treatment.

Fix

Apply the identical guarded-lookup pattern already used for 0x64 to
0x6C, 0x67, and 0x69: default to 0 (the "plain UDT" reading —
NoFamily / not built-in / not module-defined) when the attribute is
absent or the wrong length, instead of a bare dict index that raises.

Suggested validation

Any UDT whose extended-record set is missing one of these three attributes
should now export as a normal DataType with NoFamily/User/not-built-in
defaults instead of aborting the whole file.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hutcheb
hutcheb merged commit 298d271 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