From bac6b345042e18add3f83f12200af802d8efa078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Terziman?= Date: Tue, 26 Nov 2013 16:35:11 +0100 Subject: [PATCH] Removing null characters from xml parser input to avoid parsing failures --- code/irrXMLWrapper.h | 12 +++++++++++- contrib/irrXML/CXMLReaderImpl.h | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/code/irrXMLWrapper.h b/code/irrXMLWrapper.h index f5e9c3059..569347e2b 100644 --- a/code/irrXMLWrapper.h +++ b/code/irrXMLWrapper.h @@ -81,12 +81,22 @@ public: // Map the buffer into memory and convert it to UTF8. IrrXML provides its // own conversion, which is merely a cast from uintNN_t to uint8_t. Thus, // it is not suitable for our purposes and we have to do it BEFORE IrrXML - // gets the buffer. Sadly, this forces as to map the whole file into + // gets the buffer. Sadly, this forces us to map the whole file into // memory. data.resize(stream->FileSize()); stream->Read(&data[0],data.size(),1); + // Remove null characters from the input sequence otherwise the parsing will utterly fail + unsigned int size = 0; + unsigned int size_max = data.size(); + for(unsigned int i = 0; i < size_max; i++) { + if(data[i] != '\0') { + data[size++] = data[i]; + } + } + data.resize(size); + BaseImporter::ConvertToUTF8(data); } diff --git a/contrib/irrXML/CXMLReaderImpl.h b/contrib/irrXML/CXMLReaderImpl.h index 6c3afb89c..d2472b28b 100644 --- a/contrib/irrXML/CXMLReaderImpl.h +++ b/contrib/irrXML/CXMLReaderImpl.h @@ -215,7 +215,7 @@ private: { char_type* start = P; - // more forward until '<' found + // move forward until '<' found while(*P != L'<' && *P) ++P;