From c41be02511fd4db6b4d5f47c7f616352bfd128a7 Mon Sep 17 00:00:00 2001 From: Krishna Suravarapu <36037520+KrishnaSuravarapu@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:56:59 +0530 Subject: [PATCH] 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 --- .../wind/android/content/res/StringBlock.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/axmlprinter/src/main/java/wind/android/content/res/StringBlock.java b/axmlprinter/src/main/java/wind/android/content/res/StringBlock.java index ad24891..4138ce3 100644 --- a/axmlprinter/src/main/java/wind/android/content/res/StringBlock.java +++ b/axmlprinter/src/main/java/wind/android/content/res/StringBlock.java @@ -62,17 +62,22 @@ public class StringBlock { if (styleOffsetCount != 0) { block.m_styleOffsets = reader.readIntArray(styleOffsetCount); } - { - int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset; - block.m_strings = new byte[size]; - reader.readFully(block.m_strings); - } + + int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset; + block.m_strings = new byte[size]; + reader.readFully(block.m_strings); + if (stylesOffset != 0) { - int size = (chunkSize - stylesOffset); - if ((size % 4) != 0) { - throw new IOException("Style data size is not multiple of 4 (" + size + ")."); + size = (chunkSize - stylesOffset); + block.m_styles = reader.readIntArray(size / 4); + + int remaining = size % 4; + if (remaining >= 1) { + while (remaining-- > 0) { + reader.readByte(); + } } - block.m_styles = reader.readIntArray(size / 4); + } return block;