Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Oct 23, 2022
1 parent 5be5675 commit 3990f6b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/java/wstxtest/fuzz/Fuzz_DTDReadTest.java
@@ -0,0 +1,59 @@
package wstxtest.fuzz;

import com.ctc.wstx.exc.WstxLazyException;
import com.ctc.wstx.stax.WstxInputFactory;
import org.codehaus.stax2.io.Stax2ByteArraySource;
import wstxtest.stream.BaseStreamTest;

import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.Reader;

public class Fuzz_DTDReadTest extends BaseStreamTest
{
private final byte[] DOC = readResource("/fuzz/clusterfuzz-testcase-modified-XmlFuzzer-5219006592450560.txt");

private final WstxInputFactory STAX_F = getWstxInputFactory();

public void testIssueInputStream() throws Exception
{
XMLStreamReader sr = STAX_F.createXMLStreamReader(new ByteArrayInputStream(DOC));
try {
streamThrough(sr);
fail("Should not pass");
} catch (WstxLazyException e) {
verifyException(e, "FullDTDReader has reached recursion depth limit of 500");
}
sr.close();
}

public void testIssueReader() throws Exception
{
Reader r = new InputStreamReader(new ByteArrayInputStream(DOC),
"UTF-8");
XMLStreamReader sr = STAX_F.createXMLStreamReader(r);
try {
streamThrough(sr);
fail("Should not pass");
} catch (WstxLazyException e) {
verifyException(e, "FullDTDReader has reached recursion depth limit of 500");
}
sr.close();
}

public void testIssueStax2ByteArray() throws Exception
{
// Then "native" Byte array
Stax2ByteArraySource src = new Stax2ByteArraySource(DOC, 0, DOC.length);
XMLStreamReader sr = STAX_F.createXMLStreamReader(src);
try {
streamThrough(sr);
fail("Should not pass");
} catch (WstxLazyException e) {
verifyException(e, "FullDTDReader has reached recursion depth limit of 500");
}
sr.close();
}
}

0 comments on commit 3990f6b

Please sign in to comment.