Skip to content

Commit 8ac15a2

Browse files
committed
SWS-750 - SaajSoapMessageFactory's checkForUtf8ByteOrderMark is corrupting input stream
1 parent 128d5f6 commit 8ac15a2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -188,7 +188,7 @@ public SaajSoapMessage createWebServiceMessage(InputStream inputStream) throws I
188188
// "start-info", so let's try and do something about it
189189
String contentType = StringUtils
190190
.arrayToCommaDelimitedString(mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE));
191-
if (contentType.indexOf("startinfo") != -1) {
191+
if (contentType.contains("startinfo")) {
192192
contentType = contentType.replace("startinfo", "start-info");
193193
mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
194194
try {
@@ -231,16 +231,21 @@ private MimeHeaders parseMimeHeaders(InputStream inputStream) throws IOException
231231
*/
232232
private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException {
233233
PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3);
234-
byte[] bom = new byte[3];
235-
if (pushbackInputStream.read(bom) != -1) {
234+
byte[] bytes = new byte[3];
235+
int bytesRead = pushbackInputStream.read(bytes);
236+
if (bytesRead != -1) {
236237
// check for the UTF-8 BOM, and remove it if there. See SWS-393
237-
if (!(bom[0] == (byte) 0xEF && bom[1] == (byte) 0xBB && bom[2] == (byte) 0xBF)) {
238-
pushbackInputStream.unread(bom);
238+
if (!isByteOrderMark(bytes)) {
239+
pushbackInputStream.unread(bytes, 0, bytesRead);
239240
}
240241
}
241242
return pushbackInputStream;
242243
}
243244

245+
private boolean isByteOrderMark(byte[] bytes) {
246+
return bytes.length == 3 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF;
247+
}
248+
244249
/**
245250
* Template method that allows for post-processing of the given {@link SOAPMessage}.
246251
* <p>Default implementation sets {@linkplain SOAPMessage#setProperty(String, Object) message properties}, if any.

0 commit comments

Comments
 (0)