{"record":{"id":"7c0353bc7386918c","repo":"Tencent/tinker","slug":"unexpected-elf-class","errorCode":null,"errorMessage":"Unexpected elf class: {}","messagePattern":"Unexpected elf class: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareElfFile.java","lineNumber":241,"sourceCode":"            eType = restBuffer.getShort();\n            eMachine = restBuffer.getShort();\n\n            eVersion = restBuffer.getInt();\n            assertInRange(eVersion, EV_CURRENT, EV_CURRENT, \"bad elf version: \" + eVersion);\n\n            switch (eIndent[EI_CLASS]) {\n                case ELFCLASS32:\n                    eEntry = restBuffer.getInt();\n                    ePhOff = restBuffer.getInt();\n                    eShOff = restBuffer.getInt();\n                    break;\n                case ELFCLASS64:\n                    eEntry = restBuffer.getLong();\n                    ePhOff = restBuffer.getLong();\n                    eShOff = restBuffer.getLong();\n                    break;\n                default:\n                    throw new IOException(\"Unexpected elf class: \" + eIndent[EI_CLASS]);\n            }\n            eFlags = restBuffer.getInt();\n            eEhSize = restBuffer.getShort();\n            ePhEntSize = restBuffer.getShort();\n            ePhNum = restBuffer.getShort();\n            eShEntSize = restBuffer.getShort();\n            eShNum = restBuffer.getShort();\n            eShStrNdx = restBuffer.getShort();\n        }\n    }\n\n    public static class ProgramHeader {\n        // Segment types.\n        public static final int PT_NULL = 0;\n        public static final int PT_LOAD = 1;\n        public static final int PT_DYNAMIC = 2;\n        public static final int PT_INTERP = 3;\n        public static final int PT_NOTE = 4;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/shareutil/ShareElfFile.java#L223-L259","documentation":"While reading the remainder of the ELF header, ShareElfFile switches on e_ident[EI_CLASS] to read e_entry/e_phoff/e_shoff with the right widths (int for 32-bit, long for 64-bit). Any value other than ELFCLASS32(1) or ELFCLASS64(2) reaches the default branch and throws IOException('Unexpected elf class:'). Although ElfHeader.assertInRange normally rejects bad classes earlier, this branch covers arithmetic-injected or mutated class bytes and defends the width-sensitive reads.","triggerScenarios":"Parsing a file whose ELF magic is valid but whose EI_CLASS byte at offset 4 is neither 1 nor 2 — e.g. corrupted ELF, fuzzed/mutated binaries, or files crafted with invalid class identifiers.","commonSituations":"Bit-rot or partial overwrites of .so files on disk; transferring patches through channels that corrupt binary data; security research/fuzzing inputs fed to ShareElfFile.","solutions":["Treat the file as corrupt: cleanPatch() and re-apply a verified patch.","Add md5 verification of patch contents before load so corrupted .so files are rejected before ELF parsing.","Re-download the patch from the server instead of reusing a locally corrupted copy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"int elfClass = eIndent[ShareElfFile.ElfHeader.EI_CLASS] & 0xff;\nif (elfClass != ShareElfFile.ElfHeader.ELFCLASS32\n        && elfClass != ShareElfFile.ElfHeader.ELFCLASS64) {\n    throw new IOException(\"invalid elf class byte: \" + elfClass);\n}","typeGuard":null,"tryCatchPattern":"catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"elf class\")) {\n        // corrupt ELF: re-fetch the file\n    }\n}","preventionTips":["Verify checksums of patched native libs before load","Treat unexpected ELF class as corruption, never as retryable"],"tags":["tinker","android","elf","corrupted-file","file-format"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}