Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2201.7.x] Fix OOM error when parsing XML CData #41745

Merged
merged 3 commits into from
Nov 22, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public BXml parse() {
readComment(xmlStreamReader);
break;
case CDATA:
readCData(xmlStreamReader);
break;
case CHARACTERS:
readText(xmlStreamReader);
readNext = true;
Expand Down Expand Up @@ -158,6 +160,10 @@ private void readPI(XMLStreamReader xmlStreamReader) {
siblingDeque.peek().add(xmlItem);
}

private void readCData(XMLStreamReader xmlStreamReader) {
siblingDeque.peek().add(new XmlText(xmlStreamReader.getText()));
}

private void readText(XMLStreamReader xmlStreamReader) throws XMLStreamException {
StringBuilder textBuilder = new StringBuilder();
while (xmlStreamReader.getEventType() == CHARACTERS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ function fromStringTest() {
if !(d[3] is xml:Comment) {
panic error("Assertion error: not a comment");
}

string xmlString = string `<Description><![CDATA[OK]]></Description>`;
xml xmlWithCData = checkpanic xml:fromString(xmlString);
assertEquals(xmlWithCData, xml `<Description>OK</Description>`);
}

function testXmlIteratorNextInvocations() {
Expand Down
Loading