You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2012/07/31 13:19:39 UTC
svn commit: r1367499 -
/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
Author: coheigea
Date: Tue Jul 31 11:19:38 2012
New Revision: 1367499
URL: http://svn.apache.org/viewvc?rev=1367499&view=rev
Log:
[SANTUARIO-334] - UnsyncByteArrayOutputStream hangs on messages larger 512 MB
Modified:
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java?rev=1367499&r1=1367498&r2=1367499&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java Tue Jul 31 11:19:38 2012
@@ -45,6 +45,9 @@ public class UnsyncByteArrayOutputStream
}
public void write(byte[] arg0) {
+ if ((Integer.MAX_VALUE - pos) < arg0.length) {
+ throw new OutOfMemoryError();
+ }
int newPos = pos + arg0.length;
if (newPos > size) {
expandSize(newPos);
@@ -54,6 +57,9 @@ public class UnsyncByteArrayOutputStream
}
public void write(byte[] arg0, int arg1, int arg2) {
+ if ((Integer.MAX_VALUE - pos) < arg2) {
+ throw new OutOfMemoryError();
+ }
int newPos = pos + arg2;
if (newPos > size) {
expandSize(newPos);
@@ -62,7 +68,10 @@ public class UnsyncByteArrayOutputStream
pos = newPos;
}
- public void write(int arg0) {
+ public void write(int arg0) {
+ if ((Integer.MAX_VALUE - pos) == 0) {
+ throw new OutOfMemoryError();
+ }
int newPos = pos + 1;
if (newPos > size) {
expandSize(newPos);
@@ -89,7 +98,11 @@ public class UnsyncByteArrayOutputStream
private void expandSize(int newPos) {
int newSize = size;
while (newPos > newSize) {
- newSize = newSize << 2;
+ newSize = newSize << 1;
+ // Deal with overflow
+ if (newSize < 0) {
+ newSize = Integer.MAX_VALUE;
+ }
}
byte newBuf[] = new byte[newSize];
System.arraycopy(buf, 0, newBuf, 0, pos);