Fix Manifest Parse Failure (#151)

Recently encountered Multiple apps where LSPatch failed to parse
AndroidManifest.xml. Upon further debugging found that we throw an error
when style sizes don't adhere to a 4-byte boundary. We can safely ignore
this and move forward since we are anyways not using `block.m_styles`
anywhere in the code. Have checked multiple other AXML parsers wherein
they too do the same thing
This commit is contained in:
Krishna Suravarapu 2022-12-14 22:56:59 +05:30 committed by GitHub
parent 2ace2660b4
commit c41be02511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -62,17 +62,22 @@ public class StringBlock {
if (styleOffsetCount != 0) { if (styleOffsetCount != 0) {
block.m_styleOffsets = reader.readIntArray(styleOffsetCount); block.m_styleOffsets = reader.readIntArray(styleOffsetCount);
} }
{
int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset; int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset;
block.m_strings = new byte[size]; block.m_strings = new byte[size];
reader.readFully(block.m_strings); reader.readFully(block.m_strings);
}
if (stylesOffset != 0) { if (stylesOffset != 0) {
int size = (chunkSize - stylesOffset); size = (chunkSize - stylesOffset);
if ((size % 4) != 0) { block.m_styles = reader.readIntArray(size / 4);
throw new IOException("Style data size is not multiple of 4 (" + size + ").");
int remaining = size % 4;
if (remaining >= 1) {
while (remaining-- > 0) {
reader.readByte();
}
} }
block.m_styles = reader.readIntArray(size / 4);
} }
return block; return block;