{"record":{"id":"3d96cfb2f6e47b0b","repo":"Tencent/tinker","slug":"unexpected-elf-class-3d96cf","errorCode":null,"errorMessage":"Unexpected elf class: {}","messagePattern":"Unexpected elf class: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-loader/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/src/main/java/com/tencent/tinker/loader/shareutil/ShareElfFile.java#L223-L259","documentation":"In ShareElfFile.ElfHeader's constructor, after reading e_entry/e_phoff/e_shoff the switch on eIndent[EI_CLASS] falls through to default and throws IOException(\"Unexpected elf class\") for any class byte other than ELFCLASS32/ELFCLASS64. In practice the preceding assertInRange already rejects such values, so this branch is defensive; seeing it means the class byte was mutated between the two reads or assertInRange was bypassed.","triggerScenarios":"Parsing an ELF whose EI_CLASS byte is neither 1 (32-bit) nor 2 (64-bit) at the point e_entry/e_phoff/e_shoff are decoded — normally impossible because assertInRange(EI_CLASS, ELFCLASS32, ELFCLASS64, ...) runs first.","commonSituations":"Corrupted ELF file where header bytes are inconsistent; concurrent modification of the file during parsing; extremely rarely, an OEM odex container with non-standard identification bytes.","solutions":["Treat as a corrupted-file signal: pull the file and validate with readelf -h to inspect the class byte.","Delete the corrupted odex/oat so the system regenerates it, or reinstall the app.","Wrap ShareElfFile/ShareOatUtil usage in try-catch and skip oat parsing on failure.","Verify file integrity (length, md5) before parsing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"int eiClass = readEiClassByte(file); // read e_indent[4] yourself\nif (eiClass != 1 && eiClass != 2) {\n    // reject file before ShareElfFile parses it\n}","typeGuard":null,"tryCatchPattern":"try {\n    elfFile = new ShareElfFile(file);\n} catch (IOException e) {\n    // covers 'Unexpected elf class' and magic errors: treat file as corrupt, regenerate\n}","preventionTips":["Validate e_indent bytes (magic + class + data encoding) before full parsing.","Avoid concurrent writes to files being parsed.","Checksum files before parsing to catch corruption early."],"tags":["android","tinker","elf","defensive","file-corruption"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}