]> source.dussan.org Git - poi.git/commitdiff
additional safety belts to handle broken files
authorSergey Vladimirov <sergey@apache.org>
Sat, 22 Oct 2011 02:52:52 +0000 (02:52 +0000)
committerSergey Vladimirov <sergey@apache.org>
Sat, 22 Oct 2011 02:52:52 +0000 (02:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1187647 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hpsf/VariantSupport.java

index 7c351050b064a8d74c110fa3531e016a72104fd9..8b13fc0e3ce952de8be0ed4f81b17af49cd86536 100644 (file)
@@ -158,11 +158,15 @@ public class VariantSupport extends Variant
         TypedPropertyValue typedPropertyValue = new TypedPropertyValue(
                 (int) type, null );
         int unpadded;
-        try {
+        try
+        {
             unpadded = typedPropertyValue.readValue( src, offset );
-        } catch (UnsupportedOperationException exc) {
-            final byte[] v = new byte[length];
-            System.arraycopy( src, offset, v, 0, length );
+        }
+        catch ( UnsupportedOperationException exc )
+        {
+            int propLength = Math.min( length, src.length - offset );
+            final byte[] v = new byte[propLength];
+            System.arraycopy( src, offset, v, 0, propLength );
             throw new ReadingNotSupportedException( type, v );
         }