]> source.dussan.org Git - poi.git/commitdiff
Fixed bug with byte overruns.
authorGlen Stampoultzis <glens@apache.org>
Fri, 1 Mar 2002 13:10:15 +0000 (13:10 +0000)
committerGlen Stampoultzis <glens@apache.org>
Fri, 1 Mar 2002 13:10:15 +0000 (13:10 +0000)
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
src/java/org/apache/poi/hssf/record/HeaderRecord.java
src/java/org/apache/poi/util/LittleEndian.java

index 60879a67b326902f40c22eefa630cceec95b46e4..7ef88b95e717282ab61cab97af42f114e74a7667 100644 (file)
@@ -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) );
         }
     }
 
index 31946aa8ec428a0880033e06ec07b598cb856f9f..d5371b322cdbfc1beb2f39210a4e623e705d19cd 100644 (file)
@@ -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));
         }
     }
 
index 2598721725c024ad83fc7c2ac0c4727beba5911b..3d39cefc19c388dfa771fbcc35909b9df0052f27 100644 (file)
@@ -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 );
+    }
 }