Fix AOI export crashes: FILETIME overflow and unsafe attribute escaping#32
Merged
Merged
Conversation
Two real-world .ACD projects fail to export to L5X:
1. _parse_aoi_nameless converts an AOI's Created/Edited Windows FILETIME
to a datetime. On some AOI nameless records the variable-length field
walk drifts and reads 8 garbage bytes, producing a FILETIME whose year
exceeds datetime's 9999 ceiling and raising
"OverflowError: date value out of range", aborting the whole export.
2. L5xElement.to_xml serializes attribute values with html.escape, which
only handles & < > " '. When a binary field decodes to garbage (e.g. an
AOI Vendor whose length/offset drifts, decoded with errors="replace"),
the attribute ends up containing raw control characters and even raw
newlines, producing non-well-formed L5X that downstream XML parsers
reject ("open quote" / unterminated attribute).
Fixes:
- Add _filetime_to_iso(), which guards OverflowError/OSError and returns
"" for empty/out-of-range FILETIMEs; use it for both AOI dates.
- Add _escape_xml_attr(), which strips XML-1.0-illegal control characters
and encodes TAB/CR/LF as numeric character references in addition to
html.escape; use it for all attribute-value serialization.
Adds unit tests for both helpers.
Co-authored-by: Cursor <cursoragent@cursor.com>
Owner
|
Thanks @akivabrookler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two real-world
.ACDprojects fail to export to L5X. Both crashes originate inacd/l5x/elements.py:OverflowError: date value out of range—_parse_aoi_namelessconverts an AOI's Created/Edited Windows FILETIME into adatetime. On some AOI nameless records the variable-length field walk drifts and reads 8 garbage bytes, yielding a FILETIME whose year exceedsdatetime's 9999 ceiling.datetime(1601, 1, 1) + timedelta(...)then raises and aborts the entire export.Non-well-formed L5X from unsafe attribute escaping —
L5xElement.to_xmlserializes attribute values withhtml.escape, which only handles& < > " '. When a binary field decodes to garbage (e.g. an AOIVendorwhose length/offset drifts, decoded witherrors="replace"), the attribute ends up containing raw C0 control characters and even raw newlines. The emitted L5X is then non-well-formed, and strict downstream XML parsers reject it (unterminated / "open quote" attribute).Changes
_filetime_to_iso(ft): guardsOverflowError/OSErrorand returns""for empty or out-of-range FILETIMEs. Used for both the Created and Edited AOI dates (also de-duplicates the conversion that was inlined twice)._escape_xml_attr(value): strips XML-1.0-illegal control characters and encodes the legal-but-delimiting whitespace (TAB/CR/LF) as numeric character references, in addition tohtml.escape. Used for all attribute-value serialization (L5xElementBuilder.to_xml, the Communications connection name, and theRoutinename).test/test_elements_helpers.py).Testing
pytest test/test_elements_helpers.py— 7 passed).test_api.py::test_to_xml(full CuteLogix.ACD → L5X serialization, which exercises_escape_xml_attr) passes..ACDfiles that originally triggered each crash: both now export to valid, well-formed L5X.The fixes are defensive and behavior-preserving for valid input: a valid FILETIME still formats identically, and an attribute with no illegal/whitespace characters escapes exactly as before.