#574104 libxml2: considers null bytes as EOF markers

Package:
libxml2
Source:
libxml2
Description:
GNOME XML library
Submitter:
Jakub Wilk
Date:
2010-03-16 12:27:05 UTC
Severity:
normal
#574104#5
Date:
2010-03-16 11:10:03 UTC
From:
To:
libxml2 ignores null bytes (and following bytes) in an XML file:

$ printf '<test/>\0junk' | xmlwf
STDIN:1:7: not well-formed (invalid token)

$ printf '<test/>\0junk' | xmllint -
<?xml version="1.0"?>
<test/>

#574104#10
Date:
2010-03-16 11:23:05 UTC
From:
To:
For a starter, libxml2 treats your data as UTF-8, and as such uses null
terminated strings, so this is not an unexpected behaviour.

Secondly, the null character is not allowed in a xml file.

Mike

#574104#15
Date:
2010-03-16 11:37:05 UTC
From:
To:
* Mike Hommey <mh@glandium.org>, 2010-03-16, 12:23:

Huh? Why should I care about such implementation details? I care about
behaviour, which is broken. (Anyway, UTF-8 and null-terminated string
are *unrelated* concepts.)

That's my point. It is not allowed, yet xmllint happily accept files
containing it as well-formed.

#574104#22
Date:
2010-03-16 12:04:29 UTC
From:
To:
Oh, sorry for the misunderstanding.

Interestingly, it *does* recognize some brokenness due to null
characters:

$ printf '<test>ju\0nk</test>' |xmllint -
-:1: parser error : Char 0x0 out of allowed range
<test>ju
        ^
-:1: parser error : Premature end of data in tag test line 1
<test>ju
        ^

Mike

#574104#27
Date:
2010-03-16 12:25:41 UTC
From:
To:
* Mike Hommey <mh@glandium.org>, 2010-03-16, 13:04:

No problem. :)

Also, the stream parser deals with nulls bytes correctly:

$ printf '<test/>\0junk' | xmllint --stream -
-:1: parser error : Extra content at the end of the document
<test/>
        ^
- : failed to parse