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

DTD RootName only returned correctly if it consists of a multiple of 4 bytes #79

Open
Huxlyx opened this issue Dec 1, 2022 · 1 comment

Comments

@Huxlyx
Copy link

Huxlyx commented Dec 1, 2022

I encountered the following issue with version 1.3.1.
When handling a DTD event and I try to access the name of the DTD root element via AsyncXMLStreamReader, the root name is only returned in full when it consists of a multiple of 4 bytes, otherwise characters are cut off.

The issue can be reproduced with the following code:
`

public class Test {

private static final String XML =
		  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
		+ "<!DOCTYPE AnyRootName SYSTEM \"somedtd.dtd\">\r\n"
		+ "<data>somedata</data>";

public static void main(final String[] args) throws XMLStreamException {
	final AsyncXMLStreamReader<AsyncByteArrayFeeder> reader = new InputFactoryImpl().createAsyncFor(XML.getBytes(StandardCharsets.UTF_8));
	while (reader.hasNext() && ! reader.isEndElement()) {
		if (reader.next() == XMLStreamConstants.DTD) {
			System.out.println(reader.getDTDInfo().getDTDRootName());
		}
	}
}

}
`
In this case "AnyRootName" would be expected but what's actually returned from getDTDRootName() is "AnyRootN" with the last 3 characters missing, "SomeRootName" is returned in full.

While playing around a bit I also found out that if the name of the root element ends with a multi-byte character that exceeds the last four byte boundary (e.g. by changing "AnyRootName" to "AnyRootNameä"), this breaks parsing completely

Exception in thread "main" com.fasterxml.aalto.WFCException: Unexpected end-of-input in name (parsing [257])
at [row,col {unknown-source}]: [2,24]
at com.fasterxml.aalto.in.XmlScanner.reportInputProblem(XmlScanner.java:1333)
at com.fasterxml.aalto.in.XmlScanner.reportEofInName(XmlScanner.java:1430)
at com.fasterxml.aalto.in.ByteBasedScanner.addUTFPName(ByteBasedScanner.java:371)
at com.fasterxml.aalto.async.AsyncByteScanner.addPName(AsyncByteScanner.java:687)
at com.fasterxml.aalto.async.AsyncByteScanner.findPName(AsyncByteScanner.java:678)
at com.fasterxml.aalto.async.AsyncByteArrayScanner.parsePName(AsyncByteArrayScanner.java:3727)
at com.fasterxml.aalto.async.AsyncByteScanner.handleDTD(AsyncByteScanner.java:1411)
at com.fasterxml.aalto.async.AsyncByteScanner.handlePrologDeclStart(AsyncByteScanner.java:940)
at com.fasterxml.aalto.async.AsyncByteScanner.nextFromProlog(AsyncByteScanner.java:877)
at com.fasterxml.aalto.stax.StreamReaderImpl.next(StreamReaderImpl.java:790)
at mypackage.Test.main(Test.java:29)

whereas "AnyRootNäme" works and returns the whole name.

@meiMingle
Copy link

The 1.3.2 version has the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants