From 2ed5482fbf7879911aa886b4c28defe0e9342524 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 22 Oct 2011 02:52:52 +0000 Subject: [PATCH] additional safety belts to handle broken files 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 7c351050b..8b13fc0e3 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -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 ); }