From: Nick Burch Date: Sun, 19 Sep 2010 10:16:06 +0000 (+0000) Subject: Hopefully fix bug #47271 - Avoid infinite loops on broken HWPF documents with a corru... X-Git-Tag: REL_3_7_BETA3~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e1adda4edb9188aa025d04feeb7b7f3497af46d;p=poi.git Hopefully fix bug #47271 - Avoid infinite loops on broken HWPF documents with a corrupt CHP style with a parent of itself git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@998625 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 5038f83145..9123d65c13 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 47271 - Avoid infinite loops on broken HWPF documents with a corrupt CHP style with a parent of itself 49936 - Handle HWPF documents with problematic HeaderStories better 49933 - Support sections in Word 6 and Word 95 files (HWPFOldDocument) 49941 - Correctly handle space preservation of XSSFRichTextRuns when applying fonts to parts of the string diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index 647746d82e..babad02b8d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -258,6 +258,16 @@ public final class StyleSheet implements HDFType { CharacterProperties chp = sd.getCHP(); byte[] chpx = sd.getCHPX(); int baseIndex = sd.getBaseStyle(); + + if(baseIndex == istd) { + // Oh dear, this isn't allowed... + // The word file seems to be corrupted + // Switch to using the nil style so that + // there's a chance we can read it + baseIndex = NIL_STYLE; + } + + // Build and decompress the Chp if required if(chp == null && chpx != null) { CharacterProperties parentCHP = new CharacterProperties();