Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -196,20 +196,10 @@ - (void)parseBuffer: (const char*)buf withSize: (size_t)size { size_t i, last = 0; - if (finishedParsing) { - for (i = 0; i < size; i++) - if (buf[i] != ' ' && buf[i] != '\t' && - buf[i] != '\n' && buf[i] != '\r') - @throw [OFMalformedXMLException - newWithClass: isa]; - - return; - } - for (i = 0; i < size; i++) { size_t j = i; lookup_table[state](self, selectors[state], buf, &i, &last); @@ -275,10 +265,14 @@ i: (size_t*)i last: (size_t*)last { size_t len; + if (finishedParsing && buf[*i] != ' ' && buf[*i] != '\t' && + buf[*i] != '\n' && buf[*i] != '\r' && buf[*i] != '<') + @throw [OFMalformedXMLException newWithClass: isa]; + if (buf[*i] != '<') return; if ((len = *i - *last) > 0) [cache appendCStringWithoutUTF8Checking: buf + *last @@ -311,10 +305,13 @@ /* Tag was just opened */ - (void)_parseTagOpenedWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { + if (finishedParsing && buf[*i] != '!') + @throw [OFMalformedXMLException newWithClass: isa]; + switch (buf[*i]) { case '?': *last = *i + 1; state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS; level = 0; @@ -736,10 +733,13 @@ /* In \r\n "])) + + EXPECT_EXCEPTION(@"Detection of junk after the document #1", OFMalformedXMLException, [parser parseString: @"a"]) + + EXPECT_EXCEPTION(@"Detection of junk after the document #2", + OFMalformedXMLException, [parser parseString: @"