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

resources: skip padding zeroes for UTF-8 string pool

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