Skip to content
Open
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 @@ -48,8 +48,15 @@ public OMElement processDocument(InputStream inputStream, String contentType,
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
if (inputStream != null) {
try {

PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);
// Bounded for the same reason as SOAPBuilder: this reads the
// transport stream directly, and application/xml is registered in
// every shipped config, so the plain SOAP/POX ceiling was avoided
// by sending the same body with this Content-Type.
long maxRequestSize = RequestSizeLimits.resolve(messageContext,
RequestSizeLimits.SOAP_MAX_REQUEST_SIZE,
RequestSizeLimits.DEFAULT_SOAP_MAX_REQUEST_SIZE);
PushbackInputStream pushbackInputStream = new PushbackInputStream(
BoundedInputStream.wrap(inputStream, maxRequestSize));
int b;
if ((b = pushbackInputStream.read()) > 0) {
pushbackInputStream.unread(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ public OMElement processDocument(InputStream inputStream, String contentType,

OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("", "");
// Bounded for the same reason as the other builders that read the
// transport stream directly: this one copies the whole body into a
// byte[], so without a ceiling an anonymous caller sizes the allocation.
long maxRequestSize = RequestSizeLimits.resolve(msgContext,
RequestSizeLimits.SOAP_MAX_REQUEST_SIZE,
RequestSizeLimits.DEFAULT_SOAP_MAX_REQUEST_SIZE);
byte[] bytes;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(inputStream, baos, -1);
IOUtils.copy(BoundedInputStream.wrap(inputStream, maxRequestSize), baos, -1);
baos.flush();
bytes = baos.toByteArray();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.axis2.builder;

import junit.framework.TestCase;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.Parameter;
Expand Down Expand Up @@ -159,4 +160,72 @@ public void testSoapCeilingCanBeOptedOut() throws Exception {
RequestSizeLimits.SOAP_MAX_REQUEST_SIZE,
RequestSizeLimits.DEFAULT_SOAP_MAX_REQUEST_SIZE));
}

/**
* application/xml is registered for every configuration, so the plain SOAP
* ceiling was avoided by sending the same body with that Content-Type.
*/
public void testApplicationXMLBuilderIsBounded() throws Exception {
axisConfiguration.addParameter(
new Parameter(RequestSizeLimits.SOAP_MAX_REQUEST_SIZE, "64"));
try {
readPOXText(1000);
fail("An over-sized application/xml body was read in full");
} catch (Exception e) {
assertExceedsCeiling(e);
}
}

public void testApplicationXMLBuilderAcceptsABodyUnderTheCeiling() throws Exception {
axisConfiguration.addParameter(
new Parameter(RequestSizeLimits.SOAP_MAX_REQUEST_SIZE, "64"));
assertEquals("AAAAAAAA", readPOXText(8));
}

/**
* DataSourceBuilder copies the whole body into a byte[], so it was unbounded
* for any content type a deployment registers it for.
*/
public void testDataSourceBuilderIsBounded() throws Exception {
axisConfiguration.addParameter(
new Parameter(RequestSizeLimits.SOAP_MAX_REQUEST_SIZE, "64"));
try {
new DataSourceBuilder().processDocument(
new ByteArrayInputStream(new byte[4096]), "application/octet-stream",
messageContext);
fail("An over-sized body was copied in full");
} catch (Exception e) {
assertExceedsCeiling(e);
}
}

public void testDataSourceBuilderAcceptsABodyUnderTheCeiling() throws Exception {
axisConfiguration.addParameter(
new Parameter(RequestSizeLimits.SOAP_MAX_REQUEST_SIZE, "64"));
assertNotNull(new DataSourceBuilder().processDocument(
new ByteArrayInputStream(new byte[8]), "application/octet-stream",
messageContext));
}

/** Builds an application/xml body and reads its content the way a receiver does. */
private String readPOXText(int length) throws Exception {
StringBuilder sb = new StringBuilder("<a>");
for (int i = 0; i < length; i++) {
sb.append('A');
}
sb.append("</a>");
SOAPEnvelope envelope = (SOAPEnvelope) new ApplicationXMLBuilder().processDocument(
new ByteArrayInputStream(sb.toString().getBytes("UTF-8")),
"application/xml", messageContext);
return envelope.getBody().getFirstElement().getText();
}

private static void assertExceedsCeiling(Throwable t) {
for (Throwable c = t; c != null; c = c.getCause()) {
if (c.getMessage() != null && c.getMessage().contains("exceeds the configured maximum")) {
return;
}
}
fail("Expected the request-size ceiling to be hit, got " + t);
}
}