From 05347bb63d76250e797daf8bd1080539d5183550 Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Sat, 23 Jun 2007 07:44:47 +0000 Subject: [PATCH] Consistency check added when reading property set stream. An IllegalPropertyDataException is thrown if the property set stream is larger than it claims to be. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@550021 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hpsf/Section.java | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index 620a15161..3b041ed9c 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -244,6 +244,16 @@ public class Section { ple = (PropertyListEntry) propertyList.get(propertyCount - 1); ple.length = size - ple.offset; + if (ple.length <= 0) + { + final StringBuffer b = new StringBuffer(); + b.append("The property set claims to have a size of "); + b.append(size); + b.append(" bytes. However, it exceeds "); + b.append(ple.offset); + b.append(" bytes."); + throw new IllegalPropertySetDataException(b.toString()); + } } /* Look for the codepage. */ @@ -323,6 +333,20 @@ public class Section else return 1; } + + public String toString() + { + final StringBuffer b = new StringBuffer(); + b.append(getClass().getName()); + b.append("[id="); + b.append(id); + b.append(", offset="); + b.append(offset); + b.append(", length="); + b.append(length); + b.append(']'); + return b.toString(); + } }