Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cdoc/CDoc1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ CDoc1Reader::CDoc1Reader(libcdoc::DataSource *src, bool delete_on_close)
}
}
}
if(reader.hasError())
setLastError("Cannot parse container");
}

CDoc1Reader::~CDoc1Reader() noexcept
Expand Down
9 changes: 8 additions & 1 deletion cdoc/XmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ bool XMLReader::isElement(const char *elem) const
bool XMLReader::read()
{
if (!d) return false;
if (xmlTextReaderRead(d) != 1)
if (int result = xmlTextReaderRead(d); result != 1)
{
error = result < 0;
if (error)
LOG_ERROR("XMLReader: failed to parse document");
return false;
}
switch(xmlTextReaderNodeType(d))
{
case XML_READER_TYPE_DOCUMENT_TYPE:
case XML_READER_TYPE_ENTITY_REFERENCE:
error = true;
LOG_ERROR("XMLReader: document type declaration or entity reference is not allowed");
return false;
default:
return true;
Expand Down
2 changes: 2 additions & 0 deletions cdoc/XmlReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class XMLReader
bool read();
std::vector<uint8_t> readBase64();
std::string readText();
bool hasError() const { return error; }

private:
_xmlTextReader *d;
bool error = false;
};

} // namespace libcdoc
Loading