From 50226e50c1a4e2c60a0547427bd9e637c2f35ef9 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sat, 5 Aug 2023 12:21:42 -0400 Subject: [PATCH] fix: support decoding application with duplicate res entries (#3252) --- .../java/brut/androlib/res/decoder/ARSCDecoder.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index 62604d07..1b49ed58 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -328,7 +328,6 @@ public class ARSCDecoder { return mType; } - private EntryData readEntryData() throws IOException, AndrolibException { short size = mIn.readShort(); if (size < 0) { @@ -342,6 +341,12 @@ public class ARSCDecoder { } ResValue value = (flags & ENTRY_FLAG_COMPLEX) == 0 ? readValue() : readComplexEntry(); + // #2824 - In some applications the res entries are duplicated with the 2nd being malformed. + // AOSP skips this, so we will do the same. + if (value == null) { + return null; + } + EntryData entryData = new EntryData(); entryData.mFlags = flags; entryData.mSpecNamesId = specNamesId; @@ -416,7 +421,11 @@ public class ARSCDecoder { } private ResIntBasedValue readValue() throws IOException, AndrolibException { - mIn.skipCheckShort((short) 8); // size + int size = mIn.readShort(); + if (size < 8) { + return null; + } + mIn.skipCheckByte((byte) 0); // zero byte type = mIn.readByte(); int data = mIn.readInt();