Skip to content

Commit

Permalink
fix(dex-input): improve error report message for invalid dex checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Feb 26, 2024
1 parent 56749b2 commit a73c9e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private List<DexReader> load(@Nullable File file, InputStream inputStream, Strin

public DexReader loadDexReader(String fileName, byte[] content) {
if (options.isVerifyChecksum()) {
DexCheckSum.verify(content);
DexCheckSum.verify(content, fileName);
}
return new DexReader(getNextUniqId(), fileName, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

public class DexCheckSum {

public static void verify(byte[] content) {
public static void verify(byte[] content, String fileName) {
int len = content.length;
if (len < 12) {
throw new DexException("Dex file truncated, length: " + len);
throw new DexException("Dex file truncated, length: " + len + ", file: " + fileName);
}
int checksum = ByteBuffer.wrap(content, 8, 4).order(LITTLE_ENDIAN).getInt();
Adler32 adler32 = new Adler32();
adler32.update(content, 12, len - 12);
int fileChecksum = (int) (adler32.getValue());
if (checksum != fileChecksum) {
throw new DexException(String.format("Bad checksum: 0x%08x, expected: 0x%08x", fileChecksum, checksum));
throw new DexException(String.format("Bad dex file checksum: 0x%08x, expected: 0x%08x, file: %s",
fileChecksum, checksum, fileName));
}
}
}

0 comments on commit a73c9e9

Please sign in to comment.