This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new 262a31659af Revert "Apply the XML element limits to FastInfoset
messages"
262a31659af is described below
commit 262a31659afe53956b2898c6d8a915fa591a5e3d
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Nov 13 07:56:15 2026 +0000
Revert "Apply the XML element limits to FastInfoset messages"
This reverts commit 278f55250abe24166573a47731e98080ff74a3a2.
---
.../cxf/interceptor/FIStaxInInterceptor.java | 13 +-
.../java/org/apache/cxf/staxutils/StaxUtils.java | 11 +-
.../cxf/interceptor/FIStaxInInterceptorTest.java | 133 ---------------------
3 files changed, 4 insertions(+), 153 deletions(-)
diff --git
a/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
b/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
index 501eda68f3c..4337e519d6e 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
@@ -22,7 +22,6 @@ package org.apache.cxf.interceptor;
import java.io.InputStream;
-import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import com.sun.xml.fastinfoset.stax.StAXDocumentParser;
@@ -32,7 +31,6 @@ import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
-import org.apache.cxf.staxutils.StaxUtils;
/**
* Creates an XMLStreamReader from the InputStream on the Message.
@@ -53,17 +51,12 @@ public class FIStaxInInterceptor extends
AbstractPhaseInterceptor<Message> {
return
Boolean.TRUE.equals(message.containsKey(Message.REQUESTOR_ROLE));
}
- private XMLStreamReader getParser(InputStream in, Message message) {
+ private XMLStreamReader getParser(InputStream in) {
StAXDocumentParser parser = new StAXDocumentParser(in);
parser.setStringInterning(true);
parser.setForceStreamClose(true);
parser.setInputStream(in);
- try {
- // apply the same element limits as for XML
- return StaxUtils.configureReader(parser, message);
- } catch (XMLStreamException e) {
- throw new Fault(e);
- }
+ return parser;
}
public void handleMessage(Message message) {
@@ -76,7 +69,7 @@ public class FIStaxInInterceptor extends
AbstractPhaseInterceptor<Message> {
if (ct != null && ct.indexOf("fastinfoset") != -1
&& message.getContent(InputStream.class) != null
&& message.getContent(XMLStreamReader.class) == null) {
- message.setContent(XMLStreamReader.class,
getParser(message.getContent(InputStream.class), message));
+ message.setContent(XMLStreamReader.class,
getParser(message.getContent(InputStream.class)));
//add the StaxInEndingInterceptor which will close the reader
message.getInterceptorChain().add(StaxInEndingInterceptor.INSTANCE);
diff --git a/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
b/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
index ff5adcd6609..ce267af14b1 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
@@ -2118,7 +2118,7 @@ public final class StaxUtils {
}
public static boolean isSecureReader(XMLStreamReader reader, Message
message) {
- if (reader instanceof DepthRestrictingStreamReader) {
+ if (reader instanceof DocumentDepthProperties) {
return true;
}
try {
@@ -2139,15 +2139,6 @@ public final class StaxUtils {
Integer messageMaxTextLength = PropertyUtils.getInteger(message,
MAX_TEXT_LENGTH);
Long messageMaxElementCount = PropertyUtils.getLong(message,
MAX_ELEMENT_COUNT);
Long messageMaxXMLCharacters = PropertyUtils.getLong(message,
MAX_XML_CHARACTERS);
- if (!isSecureReader(xreader, message)) {
- // A reader that doesn't support the Woodstox limits, such as a
FastInfoset parser, doesn't get
- // the default limits from the input factory, so enforce the
element limits with a wrapper
- long maxElementCount = messageMaxElementCount != null ?
messageMaxElementCount : MAX_ELEMENT_COUNT_VAL;
- return new DepthRestrictingStreamReader(xreader, new
DocumentDepthProperties(
- (int)Math.min(maxElementCount, Integer.MAX_VALUE),
- messageMaxElementDepth != null ? messageMaxElementDepth :
MAX_ELEMENT_DEPTH_VAL,
- messageMaxChildElements != null ? messageMaxChildElements :
MAX_CHILD_ELEMENTS_VAL));
- }
return configureReader(xreader, messageMaxChildElements,
messageMaxElementDepth,
messageMaxAttributeCount,
messageMaxAttributeSize, messageMaxTextLength,
messageMaxElementCount,
messageMaxXMLCharacters);
diff --git
a/core/src/test/java/org/apache/cxf/interceptor/FIStaxInInterceptorTest.java
b/core/src/test/java/org/apache/cxf/interceptor/FIStaxInInterceptorTest.java
deleted file mode 100644
index ad56a1937d2..00000000000
--- a/core/src/test/java/org/apache/cxf/interceptor/FIStaxInInterceptorTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-
-import javax.xml.stream.XMLStreamReader;
-
-import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer;
-
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.staxutils.StaxUtils;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-
-public class FIStaxInInterceptorTest {
-
- @Test
- public void testReadDocument() throws Exception {
- XMLStreamReader reader = parse(nested(10), null, null);
- int elements = 0;
- while (reader.hasNext()) {
- if (reader.next() == XMLStreamReader.START_ELEMENT) {
- elements++;
- }
- }
- assertEquals(10, elements);
- }
-
- @Test
- public void testDepthLimit() throws Exception {
- // the default depth limit is 100
- readAll(parse(nested(99), null, null));
- assertThrows(RuntimeException.class, () -> readAll(parse(nested(100),
null, null)));
- }
-
- @Test
- public void testDeepNestingRejected() throws Exception {
- XMLStreamReader reader = parse(nested(100_000), null, null);
- assertThrows(RuntimeException.class, () -> readAll(reader));
- }
-
- @Test
- public void testChildElementLimit() throws Exception {
- // the default limit on child elements is 50000
- readAll(parse(children(49_999), null, null));
- assertThrows(RuntimeException.class, () ->
readAll(parse(children(50_000), null, null)));
- }
-
- @Test
- public void testLimitFromMessage() throws Exception {
- readAll(parse(nested(150), StaxUtils.MAX_ELEMENT_DEPTH, "200"));
- assertThrows(RuntimeException.class, () -> readAll(parse(nested(20),
StaxUtils.MAX_ELEMENT_DEPTH, "10")));
- }
-
- private static XMLStreamReader parse(byte[] fi, String key, String value) {
- Message message = new MessageImpl();
- Exchange exchange = new ExchangeImpl();
- exchange.setInMessage(message);
- message.setExchange(exchange);
- message.setInterceptorChain(new PhaseInterceptorChain(new
java.util.TreeSet<>()));
- message.put(Message.CONTENT_TYPE, "application/fastinfoset");
- if (key != null) {
- message.put(key, value);
- }
- message.setContent(InputStream.class, new ByteArrayInputStream(fi));
- new FIStaxInInterceptor().handleMessage(message);
- XMLStreamReader reader = message.getContent(XMLStreamReader.class);
- assertNotNull(reader);
- return reader;
- }
-
- private static void readAll(XMLStreamReader reader) throws Exception {
- while (reader.hasNext()) {
- reader.next();
- }
- }
-
- private static byte[] nested(int depth) throws Exception {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- StAXDocumentSerializer writer = new StAXDocumentSerializer(out);
- writer.writeStartDocument();
- for (int i = 0; i < depth; i++) {
- writer.writeStartElement("a");
- }
- for (int i = 0; i < depth; i++) {
- writer.writeEndElement();
- }
- writer.writeEndDocument();
- writer.close();
- return out.toByteArray();
- }
-
- private static byte[] children(int count) throws Exception {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- StAXDocumentSerializer writer = new StAXDocumentSerializer(out);
- writer.writeStartDocument();
- writer.writeStartElement("root");
- for (int i = 0; i < count; i++) {
- writer.writeEmptyElement("a");
- }
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.close();
- return out.toByteArray();
- }
-}