From dc312a53365b96724f9b9aff3b952633a5baa659 Mon Sep 17 00:00:00 2001 From: Daniel Malmqvist Date: Thu, 19 Sep 2019 13:34:06 +0200 Subject: [PATCH] Fixes issue with decoding apk containing a zero byte 9patch --- .../res/decoder/Res9patchStreamDecoder.java | 4 ++ .../brut/androlib/decode/Empty9PatchTest.java | 63 ++++++++++++++++++ .../decode/empty9patch/empty9patch.apk | Bin 0 -> 10294 bytes 3 files changed, 67 insertions(+) create mode 100644 brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/Empty9PatchTest.java create mode 100644 brut.apktool/apktool-lib/src/test/resources/decode/empty9patch/empty9patch.apk diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java index 0df77c63..ee577337 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/Res9patchStreamDecoder.java @@ -38,6 +38,10 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { try { byte[] data = IOUtils.toByteArray(in); + if (data.length == 0) { + return; + } + BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(), h = im.getHeight(); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/Empty9PatchTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/Empty9PatchTest.java new file mode 100644 index 00000000..3b2992ec --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/Empty9PatchTest.java @@ -0,0 +1,63 @@ +/** + * Copyright (C) 2019 Ryszard Wiśniewski + * Copyright (C) 2019 Connor Tumbleson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brut.androlib.decode; + +import brut.androlib.ApkDecoder; +import brut.androlib.BaseTest; +import brut.androlib.TestUtils; +import brut.common.BrutException; +import brut.directory.ExtFile; +import brut.util.OS; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertTrue; + +public class Empty9PatchTest extends BaseTest { + + @BeforeClass + public static void beforeClass() throws Exception { + TestUtils.cleanFrameworkFile(); + sTmpDir = new ExtFile(OS.createTempDirectory()); + TestUtils.copyResourceDir(Empty9PatchTest.class, "decode/empty9patch/", sTmpDir); + } + + @AfterClass + public static void afterClass() throws BrutException { + OS.rmdir(sTmpDir); + } + + @Test + public void decodeWithEmpty9PatchFile() throws BrutException, IOException { + String apk = "empty9patch.apk"; + + // decode empty9patch.apk + ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk)); + sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out"); + + apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out")); + apkDecoder.decode(); + + File aPng = new File(sTestOrigDir,"res/drawable-xhdpi/empty.9.png"); + assertTrue(aPng.isFile()); + assertTrue(aPng.length() == 0); + } +} \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/resources/decode/empty9patch/empty9patch.apk b/brut.apktool/apktool-lib/src/test/resources/decode/empty9patch/empty9patch.apk new file mode 100644 index 0000000000000000000000000000000000000000..43fb0fa275178b4ee753fea2a2a9f1ccdf8e0ef8 GIT binary patch literal 10294 zcma)C1yo$g(jEqP8$7r>1QOgO_z*N`g1fuB1%kU+zYM{sOvSLa?jFNKV%(6mqlHy{D zN=&li0mJ>4zJef_Wj^?Wmhuk}FlM32_M}Q9)t`cWO9lXt;V211BsdvO6nkwLF_sUh zCut`dES>1O0YAw4tmD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