diff options
author | Glen Stampoultzis <glens@apache.org> | 2002-03-01 13:10:15 +0000 |
---|---|---|
committer | Glen Stampoultzis <glens@apache.org> | 2002-03-01 13:10:15 +0000 |
commit | cc50a990d17581e99b94d57d161004701818755a (patch) | |
tree | 6b5373bd41d77dd1dabf923a754f954019af9274 | |
parent | f692c95cd49f8f71d3ddd5a47bc84e20dc5d0645 (diff) | |
download | poi-cc50a990d17581e99b94d57d161004701818755a.tar.gz poi-cc50a990d17581e99b94d57d161004701818755a.zip |
Fixed bug with byte overruns.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352124 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/poi/hssf/record/FooterRecord.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/HeaderRecord.java | 2 | ||||
-rw-r--r-- | 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 ); + } } |