From 2e4f27d57b70124d79b7d17e73eb47e78c0e4259 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 1 Mar 2007 15:59:56 +0000 Subject: [PATCH] If the username length in the CurrentUserAtom is clearly wrong, treat it as if there was no username, rather than giving an ArrayIndexOutOfBoundsException git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@513391 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hslf/record/CurrentUserAtom.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java index 4b49a7adc..91a548523 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -135,9 +135,20 @@ public class CurrentUserAtom // Get the username length long usernameLen = LittleEndian.getUShort(_contents,20); + if(usernameLen > 512) { + // Handle the case of it being garbage + System.err.println("Warning - invalid username length " + usernameLen + " found, treating as if there was no username set"); + usernameLen = 0; + } - // Use this to grab the revision - releaseVersion = LittleEndian.getUInt(_contents,28+(int)usernameLen); + // Now we know the length of the username, + // use this to grab the revision + if(_contents.length >= 28+(int)usernameLen + 4) { + releaseVersion = LittleEndian.getUInt(_contents,28+(int)usernameLen); + } else { + // No revision given, as not enough data. Odd + releaseVersion = 0; + } // Grab the unicode username, if stored int start = 28+(int)usernameLen+4;