Check UTF-16 endianness matches (Issue #86)

When an XML declaration specifies a UTF-16 encoding, check that
the endianness matches what the parser has already deduced.
This commit is contained in:
Rhodri James 2017-07-20 12:37:08 +01:00 committed by Sebastian Pipping
parent 611bf03530
commit 7eb3cbcec6

View file

@ -3977,7 +3977,14 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
reportDefault(parser, encoding, s, next);
if (protocolEncodingName == NULL) {
if (newEncoding) {
if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) {
/* Check that the specified encoding does not conflict with what
* the parser has already deduced. Do we have the same number
* of bytes in the smallest representation of a character? If
* this is UTF-16, is it the same endianness?
*/
if (newEncoding->minBytesPerChar != encoding->minBytesPerChar
|| (newEncoding->minBytesPerChar == 2 &&
newEncoding != encoding)) {
eventPtr = encodingName;
return XML_ERROR_INCORRECT_ENCODING;
}