From cc50a990d17581e99b94d57d161004701818755a Mon Sep 17 00:00:00 2001 From: Glen Stampoultzis Date: Fri, 1 Mar 2002 13:10:15 +0000 Subject: [PATCH] Fixed bug with byte overruns. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352124 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/record/FooterRecord.java | 2 +- src/java/org/apache/poi/hssf/record/HeaderRecord.java | 2 +- src/java/org/apache/poi/util/LittleEndian.java | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FooterRecord.java b/src/java/org/apache/poi/hssf/record/FooterRecord.java index 60879a67b3..7ef88b95e7 100644 --- a/src/java/org/apache/poi/hssf/record/FooterRecord.java +++ b/src/java/org/apache/poi/hssf/record/FooterRecord.java @@ -118,7 +118,7 @@ public class FooterRecord { field_1_footer_len = data[ 0 + offset ]; field_2_footer = new String(data, 1 + offset, - ( int ) field_1_footer_len); + LittleEndian.ubyteToInt( field_1_footer_len) ); } } diff --git a/src/java/org/apache/poi/hssf/record/HeaderRecord.java b/src/java/org/apache/poi/hssf/record/HeaderRecord.java index 31946aa8ec..d5371b322c 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/HeaderRecord.java @@ -118,7 +118,7 @@ public class HeaderRecord { field_1_header_len = data[ 0 + offset ]; field_2_header = new String(data, 1 + offset, - ( int ) field_1_header_len); + LittleEndian.ubyteToInt(field_1_header_len)); } } diff --git a/src/java/org/apache/poi/util/LittleEndian.java b/src/java/org/apache/poi/util/LittleEndian.java index 2598721725..3d39cefc19 100644 --- a/src/java/org/apache/poi/util/LittleEndian.java +++ b/src/java/org/apache/poi/util/LittleEndian.java @@ -498,4 +498,12 @@ public class LittleEndian v >>= 8; } } + + /** + * Convert an 'unsigned' byte to an integer. ie, don't carry across the sign. + */ + public static int ubyteToInt(byte b) + { + return ((b & 0x80) == 0 ? (int)b : (int)(b & (byte)0x7f) + 0x80 ); + } } -- 2.39.5