From a95a91529feaede676af11219975cc2ed2268704 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Mon, 4 Apr 2022 18:32:24 +0200 Subject: [PATCH] fix(core): ignore resource chunk entries that are located after the resource chunk end --- .../src/main/java/jadx/core/xmlgen/ResTableParser.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/xmlgen/ResTableParser.java b/jadx-core/src/main/java/jadx/core/xmlgen/ResTableParser.java index 4ff7b29fdb9..6c5554e0b14 100644 --- a/jadx-core/src/main/java/jadx/core/xmlgen/ResTableParser.java +++ b/jadx-core/src/main/java/jadx/core/xmlgen/ResTableParser.java @@ -212,7 +212,8 @@ private void parseTypeChunk(long start, PackageChunk pkg) throws IOException { /* int headerSize = */ is.readInt16(); /* int size = */ - is.readInt32(); + long chunkSize = is.readUInt32(); + long chunkEnd = start + chunkSize; int id = is.readInt8(); is.checkInt8(0, "type chunk, res0"); @@ -231,10 +232,15 @@ private void parseTypeChunk(long start, PackageChunk pkg) throws IOException { for (int i = 0; i < entryCount; i++) { entryIndexes[i] = is.readInt32(); } - is.checkPos(entriesStart, "Expected entry start"); for (int i = 0; i < entryCount; i++) { if (entryIndexes[i] != NO_ENTRY) { + if (is.getPos() >= chunkEnd) { + // Certain resource obfuscated apps like com.facebook.orca have more entries defined + // than actually fit into the chunk size -> ignore the remaining entries + LOG.warn("End of chunk reached - ignoring remaining {} entries", entryCount - i); + break; + } parseEntry(pkg, id, i, config.getQualifiers()); } }