From ea68024851ab98a7cdd6940ee1d588cafab43782 Mon Sep 17 00:00:00 2001 From: Midori Kochiya Date: Wed, 3 Dec 2025 03:14:51 +0800 Subject: [PATCH] fix(dex-input): use length in header for checksum, fix error in Dex v41 (PR #2711) * Use length in header for checksum, fix error in Dex v41 * check if length can be read, use utils method to read int values --------- Co-authored-by: Skylot <118523+skylot@users.noreply.github.com> --- .../plugins/input/dex/utils/DexCheckSum.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java b/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java index e287ae489..1175067f2 100644 --- a/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java +++ b/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java @@ -1,22 +1,22 @@ package jadx.plugins.input.dex.utils; -import java.nio.ByteBuffer; import java.util.zip.Adler32; import jadx.plugins.input.dex.DexException; -import static java.nio.ByteOrder.LITTLE_ENDIAN; - public class DexCheckSum { public static void verify(String fileName, byte[] content, int offset) { - int len = content.length; - if (len < 12) { - throw new DexException("Dex file truncated, length: " + len + ", file: " + fileName); + if (offset + 32 + 4 > content.length) { + throw new DexException("Dex file truncated, can't read file length, file: " + fileName); } - int checksum = ByteBuffer.wrap(content, offset + 8, 4).order(LITTLE_ENDIAN).getInt(); + int len = DataReader.readU4(content, offset + 32); + if (offset + len > content.length) { + throw new DexException("Dex file truncated, length in header: " + len + ", file: " + fileName); + } + int checksum = DataReader.readU4(content, offset + 8); Adler32 adler32 = new Adler32(); - adler32.update(content, 12, len - 12); + adler32.update(content, offset + 12, len - 12); int fileChecksum = (int) adler32.getValue(); if (checksum != fileChecksum) { throw new DexException(String.format("Bad dex file checksum: 0x%08x, expected: 0x%08x, file: %s",