Added a little bit of range checking.
This commit is contained in:
parent
44bb363c06
commit
2ae3f2118c
|
@ -39,6 +39,9 @@ public class AppleUtil {
|
||||||
* A word is two bytes, in standard Apple LO/HI format.
|
* A word is two bytes, in standard Apple LO/HI format.
|
||||||
*/
|
*/
|
||||||
public static int getWordValue(byte[] buffer, int offset) {
|
public static int getWordValue(byte[] buffer, int offset) {
|
||||||
|
if (offset+1 > buffer.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return getWordValue(buffer[offset], buffer[offset+1]);
|
return getWordValue(buffer[offset], buffer[offset+1]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -62,6 +65,9 @@ public class AppleUtil {
|
||||||
* Stored in standard Apple LO/HI format.
|
* Stored in standard Apple LO/HI format.
|
||||||
*/
|
*/
|
||||||
public static int get3ByteValue(byte[] buffer, int offset) {
|
public static int get3ByteValue(byte[] buffer, int offset) {
|
||||||
|
if (offset+2 > buffer.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return getUnsignedByte(buffer[offset])
|
return getUnsignedByte(buffer[offset])
|
||||||
+ getUnsignedByte(buffer[offset+1])*256
|
+ getUnsignedByte(buffer[offset+1])*256
|
||||||
+ getUnsignedByte(buffer[offset+2])*65536;
|
+ getUnsignedByte(buffer[offset+2])*65536;
|
||||||
|
|
Loading…
Reference in New Issue