Lines 35-40
Link Here
|
35 |
{ |
35 |
{ |
36 |
int length = LittleEndian.getInt( data, offset ); |
36 |
int length = LittleEndian.getInt( data, offset ); |
37 |
|
37 |
|
|
|
38 |
// If the length looks wrong, this might be because the offset is expected to be on a |
39 |
// 4 byte boundary. Try changing it rather than getting an ArrayIndexOutOfBoundsException |
40 |
// from LittleEndian.getByteArray. Also avoids creating a large byte[] if this is the case. |
41 |
if (!validLength( length, data, offset + LittleEndian.INT_SIZE )) |
42 |
{ |
43 |
if (offset % 4 != 0) |
44 |
{ |
45 |
offset += 2; |
46 |
} |
47 |
|
48 |
length = LittleEndian.getInt( data, offset ); |
49 |
|
50 |
if (!validLength(length, data, offset + LittleEndian.INT_SIZE)) |
51 |
{ |
52 |
throw new IllegalPropertySetDataException( |
53 |
"UnicodeString started at offset #" + offset |
54 |
+ " is not NULL-terminated" ); |
55 |
} |
56 |
} |
57 |
|
38 |
if ( length == 0 ) |
58 |
if ( length == 0 ) |
39 |
{ |
59 |
{ |
40 |
_value = new byte[0]; |
60 |
_value = new byte[0]; |
Lines 43-55
Link Here
|
43 |
|
63 |
|
44 |
_value = LittleEndian.getByteArray( data, offset |
64 |
_value = LittleEndian.getByteArray( data, offset |
45 |
+ LittleEndian.INT_SIZE, length * 2 ); |
65 |
+ LittleEndian.INT_SIZE, length * 2 ); |
46 |
|
|
|
47 |
if ( _value[length * 2 - 1] != 0 || _value[length * 2 - 2] != 0 ) |
48 |
throw new IllegalPropertySetDataException( |
49 |
"UnicodeString started at offset #" + offset |
50 |
+ " is not NULL-terminated" ); |
51 |
} |
66 |
} |
52 |
|
67 |
|
|
|
68 |
private boolean validLength(int length, byte[] data, int offset) { |
69 |
if (length == 0) |
70 |
{ |
71 |
return true; |
72 |
} |
73 |
int size = length * 2; |
74 |
offset += size; |
75 |
return offset < data.length && size >= 0 && data[offset-1] == 0 && data[offset-2] == 0; |
76 |
} |
77 |
|
53 |
int getSize() |
78 |
int getSize() |
54 |
{ |
79 |
{ |
55 |
return LittleEndian.INT_SIZE + _value.length; |
80 |
return LittleEndian.INT_SIZE + _value.length; |