From ef6bf6e99d0761ca49b15787a575a0bec1be1597 Mon Sep 17 00:00:00 2001 From: Andreas Rossbacher Date: Mon, 12 Oct 2020 10:27:50 -0700 Subject: [PATCH] Do ResourceTableChunk precheck with 0 as it might have 0 entries (e.g. split apk for abi) Allow TypeSpecChunk to be null as this can happen. --- .../devrel/gmscore/tools/apk/arsc/PackageChunk.java | 10 ++++++++-- .../tools/apk/arsc/ResourceEntryStatsCollector.java | 4 +++- .../gmscore/tools/apk/arsc/ResourceTableChunk.java | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/java/com/google/devrel/gmscore/tools/apk/arsc/PackageChunk.java b/java/com/google/devrel/gmscore/tools/apk/arsc/PackageChunk.java index 4081bc4..16f350a 100644 --- a/java/com/google/devrel/gmscore/tools/apk/arsc/PackageChunk.java +++ b/java/com/google/devrel/gmscore/tools/apk/arsc/PackageChunk.java @@ -197,9 +197,15 @@ public Collection getTypeSpecChunks() { return typeSpecs.values(); } - /** For a given (1-based) type id, returns the {@link TypeSpecChunk} matching it. */ + /** + * For a given (1-based) type id, returns the {@link TypeSpecChunk} matching it. + */ public TypeSpecChunk getTypeSpecChunk(int id) { - return Preconditions.checkNotNull(typeSpecs.get(id)); + if (typeSpecs.containsKey(id)) { + return typeSpecs.get(id); + } else { + return null; + } } /** diff --git a/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceEntryStatsCollector.java b/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceEntryStatsCollector.java index c223101..a5705df 100644 --- a/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceEntryStatsCollector.java +++ b/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceEntryStatsCollector.java @@ -174,7 +174,9 @@ private void computeTypeSpecSizes(PackageChunk packageChunk, // The 1 here is to convert back to a 1-based index. TypeSpecChunk typeSpec = packageChunk.getTypeSpecChunk(i + 1); // TypeSpecChunk entries share everything equally. - addSizes(usages[i], typeSpec.getOriginalChunkSize(), 0, 1); + if (typeSpec != null) { + addSizes(usages[i], typeSpec.getOriginalChunkSize(), 0, 1); + } } } diff --git a/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceTableChunk.java b/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceTableChunk.java index e5fc483..045fe9d 100644 --- a/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceTableChunk.java +++ b/java/com/google/devrel/gmscore/tools/apk/arsc/ResourceTableChunk.java @@ -49,7 +49,7 @@ public class ResourceTableChunk extends ChunkWithChunks { protected ResourceTableChunk(ByteBuffer buffer, @Nullable Chunk parent) { super(buffer, parent); // packageCount. We ignore this, because we already know how many chunks we have. - Preconditions.checkState(buffer.getInt() >= 1, "ResourceTableChunk package count was < 1."); + Preconditions.checkState(buffer.getInt() >= 0, "ResourceTableChunk package count was < 0."); } @Override