]> source.dussan.org Git - poi.git/commitdiff
Improvements to arg checking in constructor
authorJosh Micich <josh@apache.org>
Wed, 3 Dec 2008 23:35:18 +0000 (23:35 +0000)
committerJosh Micich <josh@apache.org>
Wed, 3 Dec 2008 23:35:18 +0000 (23:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723141 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java

index b3ded97687eff06cfaf660681b3a55b89e781387..0320734b2d60023b4bfb73e8d6d38fb2f62b7d9a 100644 (file)
@@ -30,9 +30,17 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
        private int _writeIndex;
 
        public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset, int maxWriteLen) {
+               if (startOffset < 0 || startOffset > buf.length) {
+                       throw new IllegalArgumentException("Specified startOffset (" + startOffset 
+                                       + ") is out of allowable range (0.." + buf.length + ")");
+               }
                _buf = buf;
                _writeIndex = startOffset;
                _endIndex = startOffset + maxWriteLen;
+               if (_endIndex < startOffset ||  _endIndex > buf.length) {
+                       throw new IllegalArgumentException("calculated end index (" + _endIndex 
+                                       + ") is out of allowable range (" + _writeIndex + ".." + buf.length + ")");
+               }
        }
        public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset) {
                this(buf, startOffset, buf.length - startOffset);
@@ -91,7 +99,7 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
        }
        public LittleEndianOutput createDelayedOutput(int size) {
                checkPosition(size);
-               LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, _writeIndex+size);
+               LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size);
                _writeIndex += size;
                return result;
        }