Skip to content

Expected either attr limit (2147483647) >= currAttrSize (0) OR >= outBuf.length (96) #122

@j3rem1e

Description

@j3rem1e

After upgrading my application to woodstock v6.2.x, importing xml failed with this exception :

Caused by: java.lang.RuntimeException: Internal error: Expected either attr limit (2147483647) >= currAttrSize (0) OR >= outBuf.length (96)
	at com.ctc.wstx.util.ExceptionUtil.throwInternal(ExceptionUtil.java:69) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader._checkAttributeLimit(BasicStreamReader.java:2056) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.parseAttrValue(BasicStreamReader.java:2038) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:3144) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:3042) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.handleRootElem(BasicStreamReader.java:2188) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2168) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1180) ~[?:?]

downgrading to v6.0.2 fixes it.

I don't really understand what the message means.. ;)

The code looks like the following :

public static void checkSVG(final String svg) {
	boolean allowed = true;

	XMLInputFactory factory = XMLInputFactory.newInstance();
	factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
	factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
	factory.setProperty("com.ctc.wstx.maxAttributeSize", Integer.MAX_VALUE);

	XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(svg))
	try {
		while (reader.hasNext()) {
			if (reader.next() == XMLEvent.START_ELEMENT) {

				if (!WHITELIST_ELEMENTS.contains(reader.getLocalName())) {
					allowed = false;
				}
				
				int attcount = reader.getAttributeCount();
				for (int i = 0; i < attcount; ++i) {
					String attName = reader.getAttributeLocalName(i); 
					if (!WHITELIST_ATTRIBUTES.contains(attName)) {
						allowed = false;
					}
				}
			}
		}
	} catch (final XMLStreamException e) {
		ExceptionUtils.throwRuntimeException(e);
	}
	
	if (!allowed) {
		throw new SecurityException("xxx");
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions