Tencent/matrix · error · DexDataException
Endian constant has unexpected value
Error message
Endian constant has unexpected value ${Integer.toHexString(mHeaderItem.endianTag)} What it means
After magic validation, DexData.parseHeaderItem reads the endian tag, which must equal ENDIAN_CONSTANT (0x12345678, little-endian) or REVERSE_ENDIAN_CONSTANT (0x78563412, big-endian). Any other value means the header is corrupt or the file isn't really a dex despite passing the magic check; it throws DexDataException.
Solutions
- Rebuild or re-obtain the dex; a bad endian tag almost always means corruption.
- Check endianness handling in whatever wrote/modified the dex — byte-swapped headers indicate a broken repacking tool.
- Verify with `dexdump` or `d8` that the file opens in standard tooling; if not, the file is bad, not this library.
- Compare file size and checksum/signature fields against the APK's copy to detect truncation.
Example fix
// before
DexData dexData = new DexData(raf);
dexData.load(); // throws on bad endian tag
// after
try {
dexData.load();
} catch (DexDataException e) {
MatrixLog.w(TAG, "corrupt dex header, skipping: " + inputPath);
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify dex integrity via header before load byte[] header = readBytes(f, 0, 112); int endianTag = ByteBuffer.wrap(header, 40, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(); boolean ok = endianTag == 0x78563412L || endianTag == 0x12345678L;
Try / catch
try {
dexData.load();
} catch (DexDataException e) {
Log.w(TAG, "corrupt dex header (bad endian tag), skipping " + inputPath);
} Prevention
- Check the dex file size matches the header's fileSize field to detect truncation.
- Avoid post-processing tools that rewrite dex headers without fixing endian/checksum fields.
- Validate with standard tooling (dexdump) when a dex repeatedly fails.
- Re-transfer/rebuild files that fail — bad endian tag means corruption, not a config issue.
When it happens
Trigger: parseHeaderItem (via load) reads an endianTag other than the two defined constants — bit-rotated/truncated dex, a file that coincidentally starts with dex magic but has damaged header, or wrong-offset reads caused by prior parsing bugs.
Common situations: Corrupted dexes from interrupted builds or bad file transfer; dexes modified by post-processing tools (repackaging, optimization) that broke the header; exotic big-endian-produced artifacts mis-handled by tooling.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/7fc982ed28d078c3.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-commons/src/main/java/com/android/dexdeps/DexData.java:108
+ "this is a DEX file?");
throw new DexDataException();
}
/*
* Read the endian tag, so we properly swap things as we read
* them from here on.
*/
seek(8 + 4 + 20 + 4 + 4);
mHeaderItem.endianTag = readInt();
if (mHeaderItem.endianTag == HeaderItem.ENDIAN_CONSTANT) {
/* do nothing */
} else if (mHeaderItem.endianTag == HeaderItem.REVERSE_ENDIAN_CONSTANT) {
/* file is big-endian (!), reverse future reads */
isBigEndian = true;
} else {
System.err.println("Endian constant has unexpected value "
+ Integer.toHexString(mHeaderItem.endianTag));
throw new DexDataException();
}
seek(8 + 4 + 20); // magic, checksum, signature
mHeaderItem.fileSize = readInt();
mHeaderItem.headerSize = readInt();
/*mHeaderItem.endianTag =*/ readInt();
/*mHeaderItem.linkSize =*/ readInt();
/*mHeaderItem.linkOff =*/ readInt();
/*mHeaderItem.mapOff =*/ readInt();
mHeaderItem.stringIdsSize = readInt();
mHeaderItem.stringIdsOff = readInt();
mHeaderItem.typeIdsSize = readInt();
mHeaderItem.typeIdsOff = readInt();
mHeaderItem.protoIdsSize = readInt();
mHeaderItem.protoIdsOff = readInt();
mHeaderItem.fieldIdsSize = readInt();
mHeaderItem.fieldIdsOff = readInt();
mHeaderItem.methodIdsSize = readInt();View on GitHub (pinned to 3b8293bd65)