{"record":{"id":"2ca0e08bb48673c1","repo":"pxb1988/dex2jar","slug":"bad-payload-offset-for-s","errorCode":null,"errorMessage":"bad payload offset for %s","messagePattern":"bad payload offset for (.+?)","errorType":"exception","errorClass":"BadOpException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java","lineNumber":1260,"sourceCode":"                        case 0x02:// sparse-switch-data\r\n                        {\r\n                            int size = ushort(insns, u1SwitchData + 2);\r\n                            int b = u1SwitchData + 4 + 4 * size;// targets\r\n                            for (int i = 0; i < size; i++) {\r\n                                target = offset + sint(insns, b + i * 4);\r\n                                if (target < 0 || target * 2 > insns.length ) {\r\n                                    throw new BadOpException(\"jump out of insns %s -> %04x\", op, target);\r\n                                }\r\n                                q.add(target);\r\n                                order(labelsMap, target);\r\n                            }\r\n                            break;\r\n                        }\r\n                        default:\r\n                            throw new BadOpException(\"bad payload for %s\", op);\r\n                    }\r\n            } else {\r\n                throw new BadOpException(\"bad payload offset for %s\", op);\r\n            }\r\n        }\r\n\r\n        if (canContinue) {\r\n            int idx = Integer.MAX_VALUE;\r\n            switch (op.indexType) {\r\n            case kIndexStringRef:\r\n                if (op.format == InstructionFormat.kFmt31c) {\r\n                    idx = uint(insns, u1offset + 2);\r\n                } else {// other\r\n                    idx = ushort(insns, u1offset + 2);\r\n                }\r\n                canContinue = idx >= 0 && idx < string_ids_size;\r\n                break;\r\n            case kIndexTypeRef:\r\n                idx = ushort(insns, u1offset + 2);\r\n                canContinue = idx < type_ids_size;\r\n                break;\r","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java#L1242-L1278","documentation":"DexFileReader throws BadOpException when an instruction's declared payload offset does not point inside the insns array at all (the u1SwitchData/u1payload offset check fails before any payload type is examined). This means the bytecode references data outside the code unit, which cannot happen in a valid dex.","triggerScenarios":"Decoding a dex where a switch or fill-array-data instruction carries a payload offset that resolves outside the method's insns array, e.g. offset <= 0 or beyond the array length.","commonSituations":"Corrupted or truncated dex files; dex files modified by anti-analysis protections; inputs produced by broken dex writers.","solutions":["Confirm the dex is complete and unmodified (compare checksum/signature in the dex header).","Rebuild the dex from source or re-extract it from the APK.","Pre-scan with dexdump/apkanalyzer to identify malformed methods.","Catch BadOpException and skip the offending method if full-file conversion is not required."],"exampleFix":"// before\ndexReader.accept(visitor, 0);\n// after\ntry {\n    dexReader.accept(visitor, 0);\n} catch (BadOpException e) {\n    LOG.warn(\"bad payload offset: \" + e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// check dex integrity first: header checksum\nint stored = ByteBuffer.wrap(data, 8, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();\nChecksum cs = new CRC32(); cs.update(data, 12, data.length - 12);\nif ((int) cs.getValue() != stored) throw new IllegalArgumentException(\"dex checksum mismatch\");","typeGuard":null,"tryCatchPattern":"try {\n    dexReader.accept(visitor, 0);\n} catch (BadOpException e) {\n    LOG.warn(\"bad payload offset: \" + e.getMessage());\n}","preventionTips":["Check dex header checksum before processing","Re-extract dex from APK instead of copying partial files","Treat BadOpException as a per-method skip, not a fatal error"],"tags":["dex","android","bytecode","corrupt-input"],"backgroundTag":"malformed-dex-opcode","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}