{"record":{"id":"5968417c8795c01c","repo":"gchq/CyberChef","slug":"disassembly-failed-e","errorCode":null,"errorMessage":"Disassembly failed: ${e}","messagePattern":"Disassembly failed: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/DisassembleARM.mjs","lineNumber":158,"sourceCode":"        }\n\n        let disassembler;\n        try {\n            disassembler = new cs.Capstone(arch, modeValue);\n        } catch (e) {\n            throw new OperationError(`Failed to initialise Capstone disassembler: ${e}`);\n        }\n\n        let instructions;\n        try {\n            instructions = disassembler.disasm(bytes, startAddress);\n        } catch (e) {\n            disassembler.close();\n            // Check if it's a \"no valid instructions\" error (code 0 means OK but nothing decoded)\n            if (e && e.includes && e.includes(\"code 0:\")) {\n                throw new OperationError(`No valid ${architecture} instructions found in input. The bytes may be for a different architecture or mode.`);\n            }\n            throw new OperationError(`Disassembly failed: ${e}`);\n        }\n\n        // Format output\n        const output = [];\n        for (const insn of instructions) {\n            let line = \"\";\n\n            if (showPosition) {\n                // Format address as hex with 0x prefix\n                const addrHex = \"0x\" + insn.address.toString(16).padStart(8, \"0\");\n                line += addrHex + \"  \";\n            }\n\n            if (showHex) {\n                // Format instruction bytes as hex\n                const bytesHex = insn.bytes.map(b => b.toString(16).padStart(2, \"0\")).join(\"\");\n                line += bytesHex.padEnd(16, \" \") + \"  \";\n            }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/DisassembleARM.mjs#L140-L176","documentation":"Thrown by Disassemble ARM run() inside the disasm catch for any capstone disassembly error that is NOT the 'code 0:' (no instructions) case. The original exception is stringified. This covers genuine capstone failures during disasm(): invalid memory access in WASM, unexpected internal errors, unsupported instruction edge cases, or a thrown JS error from the binding.","triggerScenarios":"disassembler.disasm(bytes, startAddress) raises with a message that does not contain 'code 0:'. Could be an out-of-range startAddress producing an internal error, a capstone internal fault, a WASM memory error on very large inputs, or an exception type without an .includes method (the guard checks e && e.includes).","commonSituations":"A very large input exhausting WASM linear memory; a non-string exception object from the binding (the guard's e.includes check defends this and falls through to this branch); an internal capstone bug triggered by specific byte patterns; an invalid startAddress.","solutions":["Reduce the input size and retry to rule out WASM memory limits.","Verify startAddress is a sane non-negative integer.","Try a different Architecture/Mode/Endianness to rule out an instruction-edge-case fault.","Capture the exact exception text from the error message and report if it indicates a capstone-js binding bug.","Update @alexaltea/capstone-js to the latest version."],"exampleFix":"// before - multi-megabyte hex input exhausting WASM memory\ninput: <several MB of hex>\n\n// after - disassemble in smaller chunks\ninput: <first 64KB of hex>","handlingStrategy":"try-catch","validationCode":"// bound input size to avoid WASM memory exhaustion\nfunction isReasonableInputSize(hexInput) {\n    const bytes = hexInput.replace(/\\s/g, \"\").length / 2;\n    return bytes > 0 && bytes < 1_000_000; // < ~1MB\n}","typeGuard":"/** @returns {boolean} */\nfunction isReasonableHexInputSize(s) {\n    const digits = typeof s === \"string\" ? s.replace(/\\s/g, \"\").length : 0;\n    return digits > 0 && digits % 2 === 0 && digits / 2 < 1_000_000;\n}","tryCatchPattern":"try {\n    out = await disassembleArm.run(input, args);\n} catch (e) {\n    if (e instanceof OperationError && /Disassembly failed/.test(e.message)) {\n        // reduce input size, verify startAddress, try a different arch/mode, then retry\n    } else throw e;\n}","preventionTips":["Disassemble large binaries in chunks (<1MB) to avoid WASM memory limits.","Keep startAddress a non-negative integer within a sane range.","Try alternate Architecture/Mode/Endianness to rule out edge-case faults.","Update @alexaltea/capstone-js if the error points to a binding bug."],"tags":["disassembly","arm","capstone","runtime"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}