Skip to content

dom: ignore NUL padding at the end of the xml data - #1146

Merged
EmmanuelP merged 1 commit into
AravisProject:mainfrom
Keval-P:dom-trailing-nul
Dec 2, 2026
Merged

EmmanuelP merged 1 commit into
AravisProject:mainfrom
Keval-P:dom-trailing-nul

Conversation

@Keval-P

@Keval-P Keval-P commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #1102.

Some cameras pad their GenICam XML with NUL bytes and count them in the size from the Local: URL (the SVS-Vistek one in the issue ends with </RegisterDescription>\n\0\0). With libxml2 2.11 or newer, _parse_memory() uses xmlCtxtReadMemory(), which rejects the padding with "Extra content at the end of the document", and the device fails to open with "Invalid Genicam data". The older xmlSAXUserParseMemory() path accepts it, which is probably why this only shows up on some systems.

This change strips trailing NUL bytes from the size before the buffer goes to libxml2, in both _parse_memory() variants. It's the same idea xiaoqiangwang tested in the issue comments. A negative size still means strlen().

Testing: I added a /dom/trailing-nul case to tests/dom.c that parses a small GenICam document followed by two NUL bytes, through both arv_dom_document_new_from_memory() and arv_gc_new(). I built against libxml2 2.13.8: the test fails on main ("Invalid document") and passes with the fix. With the system libxml2 2.9.13 it passes either way. meson test passes all 7 suites, including fakegv, against both libxml2 versions. I don't have the camera, so I haven't tried it on real hardware.

Some devices pad their Genicam data with NUL bytes and include them in
the size they announce. libxml2 2.11 and later reject them with "Extra
content at the end of the document", so the device fails to open with
"Invalid Genicam data". Older libxml2 versions accepted them.

Drop trailing NUL bytes from the size before handing the buffer to
libxml2.

Fixes AravisProject#1102
@EmmanuelP
EmmanuelP merged commit bd480cf into AravisProject:main Dec 2, 2026
5 checks passed
@EmmanuelP

Copy link
Copy Markdown
Contributor

Thanks

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.

GenICam XML parsing fails when local XML contains trailing NUL padding

2 participants