Skip to content

fix: fall back to len(children) on malformed numchildren - #124

Merged
s2x merged 3 commits into
crazy-goat:mainfrom
Furox-Art:fix/lenient-numchildren
Oct 13, 2026
Merged

s2x merged 3 commits into
crazy-goat:mainfrom
Furox-Art:fix/lenient-numchildren

Conversation

@Furox-Art

Copy link
Copy Markdown
Contributor

Closes #100

What

numchildren="abc" (or an overflowing value) made encoding/xml fail the whole response, because xProp.NumChildren is a strict int and rawLocked treats any parse error as fatal — a cosmetic engine quirk became a hard command failure. #98 reintroduced the attribute as a strict int; before #35 it was unknown to the decoder and ignored.

xProp now decodes numchildren leniently: a malformed or out-of-range value falls back to 0, and summarize's existing max(p.NumChildren, len(p.Children)) reports the received page size.

A type-level UnmarshalXMLAttr alone is not sufficient — it makes the struct's int fields opaque to the decoder — so xProp also implements UnmarshalXML, binding the remaining fields through a shadow struct. Nested property decoding is unchanged.

Tests

New cases in dbgp_test.go cover malformed ("abc"), negative (-5) and overflowing (99999999999999999999999) values: each parses without error and renders the received page size.

$ go test -race -count=1 -run 'TestUnmarshal|TestSummarize|TestDecode|TestReadPacket|TestQuoteArg' -v .
--- PASS: TestUnmarshalMalformedNumChildren (0.00s)
    --- PASS: .../malformed_numchildren
    --- PASS: .../negative_numchildren
    --- PASS: .../overflowing_numchildren
ok  github.com/crazy-goat/xdbg

Note on the full suite

TestToolsCallListenBadInit fails in this environment, but it fails identically on a pristine main checkout (verified with git stash — same subtests, same "no engine connected within 10s" error). It looks network/timing-dependent in WSL, not related to this change. CI on GitHub's runners is the authoritative gate.

Furox-Art and others added 3 commits October 12, 2026 00:52
Closes #100

A non-numeric or overflowing numchildren attribute made the whole
DBGp response fail to parse, because encoding/xml decodes struct
integer attributes strictly and rawLocked treats any parse error as
fatal. Before #35 the attribute was unknown to the decoder and so was
ignored; #98 reintroduced it as a strict int, turning a cosmetic
engine quirk into a hard command failure.

xProp now decodes numchildren leniently: a malformed or out-of-range
value falls back to 0, and summarize's max(p.NumChildren,
len(p.Children)) then reports the received page size. A type-level
UnmarshalXMLAttr is not enough on its own — it makes the int fields
opaque to the decoder — so xProp also implements UnmarshalXML to bind
the remaining fields through a shadow struct, keeping nested property
decoding intact.

Tests cover malformed, negative and overflowing values.
@s2x
s2x merged commit ce44199 into crazy-goat:main Oct 13, 2026
6 checks passed
@s2x

s2x commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thank you @Furox-Art for this fix! I added a CHANGELOG entry, space trimming and a nested test on top, and merged it.

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.

bug: a malformed numchildren attribute fails the whole DBGp response after #35

2 participants