提交 7fb39881 编写于 作者: S Skylot

resources: skip padding zeroes for UTF-8 string pool

上级 a5035278
...@@ -27,6 +27,7 @@ public class CommonBinaryParser extends ParserConstants { ...@@ -27,6 +27,7 @@ public class CommonBinaryParser extends ParserConstants {
int[] stylesOffset = is.readInt32Array(styleCount); int[] stylesOffset = is.readInt32Array(styleCount);
is.checkPos(start + stringsStart, "Expected strings start"); is.checkPos(start + stringsStart, "Expected strings start");
long stringsEnd = stylesStart == 0 ? chunkEnd : start + stylesStart;
String[] strings = new String[stringCount]; String[] strings = new String[stringCount];
if ((flags & UTF8_FLAG) != 0) { if ((flags & UTF8_FLAG) != 0) {
// UTF-8 // UTF-8
...@@ -34,10 +35,10 @@ public class CommonBinaryParser extends ParserConstants { ...@@ -34,10 +35,10 @@ public class CommonBinaryParser extends ParserConstants {
// is.checkPos(start + stringsStart + stringsOffset[i], "Expected string start"); // is.checkPos(start + stringsStart + stringsOffset[i], "Expected string start");
strings[i] = is.readString8(); strings[i] = is.readString8();
} }
is.skipToPos(stringsEnd, "Skip string8 padding");
} else { } else {
// UTF-16 // UTF-16
long end = stylesStart == 0 ? chunkEnd : start + stylesStart; byte[] strArray = is.readInt8Array((int) (stringsEnd - is.getPos()));
byte[] strArray = is.readInt8Array((int) (end - is.getPos()));
for (int i = 0; i < stringCount; i++) { for (int i = 0; i < stringCount; i++) {
// don't trust specified string length, read until \0 // don't trust specified string length, read until \0
// stringsOffset can be same for different indexes // stringsOffset can be same for different indexes
...@@ -51,7 +52,7 @@ public class CommonBinaryParser extends ParserConstants { ...@@ -51,7 +52,7 @@ public class CommonBinaryParser extends ParserConstants {
} }
} }
// skip padding zeroes // skip padding zeroes
is.skip(chunkEnd - is.getPos()); is.skipToPos(chunkEnd, "Skip string pool padding");
return strings; return strings;
} }
......
...@@ -143,12 +143,8 @@ public class ParserStream { ...@@ -143,12 +143,8 @@ public class ParserStream {
long pos = getPos(); long pos = getPos();
if (pos < expectedOffset) { if (pos < expectedOffset) {
skip(expectedOffset - pos); skip(expectedOffset - pos);
pos = getPos();
}
if (pos != expectedOffset) {
throw new IOException(error + ", expected offset: 0x" + Long.toHexString(expectedOffset)
+ ", actual: 0x" + Long.toHexString(pos));
} }
checkPos(expectedOffset, error);
} }
public int decodeLength8() throws IOException { public int decodeLength8() throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册