From 9aebc04aef9bf913367c08c53aaad3b231c450a0 Mon Sep 17 00:00:00 2001 From: Jason Height Date: Wed, 17 Sep 2003 05:34:29 +0000 Subject: [PATCH] Fixed zero length Label string reading Fixed incorrect offset for uncompressed unicode git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353355 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/LabelRecord.java | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/LabelRecord.java b/src/java/org/apache/poi/hssf/record/LabelRecord.java index 950a7cc093..7c58edd08f 100644 --- a/src/java/org/apache/poi/hssf/record/LabelRecord.java +++ b/src/java/org/apache/poi/hssf/record/LabelRecord.java @@ -150,15 +150,17 @@ public class LabelRecord field_3_xf_index = LittleEndian.getShort(data, 4 + offset); field_4_string_len = LittleEndian.getShort(data, 6 + offset); field_5_unicode_flag = data[ 8 + offset ]; - if (isUnCompressedUnicode()) - { - field_6_value = StringUtil.getFromUnicodeBE(data, 8 + offset, - field_4_string_len); - } - else - { - field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, getStringLength()); - } + if (field_4_string_len > 0) { + if (isUnCompressedUnicode()) + { + field_6_value = StringUtil.getFromUnicodeBE(data, 9 + offset, + field_4_string_len); + } + else + { + field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, getStringLength()); + } + } else field_6_value = null; } /* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! @@ -237,6 +239,27 @@ public class LabelRecord return this.sid; } + public String toString() + { + StringBuffer buffer = new StringBuffer(); + buffer.append("[LABEL]\n"); + buffer.append(" .row = ") + .append(Integer.toHexString(getRow())).append("\n"); + buffer.append(" .column = ") + .append(Integer.toHexString(getColumn())).append("\n"); + buffer.append(" .xfindex = ") + .append(Integer.toHexString(getXFIndex())).append("\n"); + buffer.append(" .string_len = ") + .append(Integer.toHexString(field_4_string_len)).append("\n"); + buffer.append(" .unicode_flag = ") + .append(Integer.toHexString(field_5_unicode_flag)).append("\n"); + buffer.append(" .value = ") + .append(getValue()).append("\n"); + buffer.append("[/LABEL]\n"); + return buffer.toString(); + } + + public boolean isBefore(CellValueRecordInterface i) { if (this.getRow() > i.getRow())