{"record":{"id":"6bc0017a73e549ed","repo":"gchq/CyberChef","slug":"could-not-decode-messagepack-to-json-err","errorCode":null,"errorMessage":"Could not decode MessagePack to JSON: ${err}","messagePattern":"Could not decode MessagePack to JSON: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromMessagePack.mjs","lineNumber":41,"sourceCode":"        this.module = \"Code\";\n        this.description = \"Converts MessagePack encoded data to JSON. MessagePack is a computer data interchange format. It is a binary form for representing simple data structures like arrays and associative arrays.\";\n        this.infoURL = \"https://wikipedia.org/wiki/MessagePack\";\n        this.inputType = \"ArrayBuffer\";\n        this.outputType = \"JSON\";\n        this.args = [];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {JSON}\n     */\n    run(input, args) {\n        try {\n            const buf = Buffer.from(new Uint8Array(input));\n            return notepack.decode(buf);\n        } catch (err) {\n            throw new OperationError(`Could not decode MessagePack to JSON: ${err}`);\n        }\n    }\n\n}\n\nexport default FromMessagePack;\n","sourceCodeStart":23,"sourceCodeEnd":48,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromMessagePack.mjs#L23-L48","documentation":"Thrown by From MessagePack when notepack.decode() throws on the input buffer. Any decode failure (truncated data, invalid byte markers, type mismatch, non-MessagePack bytes) is caught and rethrown as this OperationError with the underlying error appended. The op accepts an ArrayBuffer and converts it to a Node Buffer before decoding.","triggerScenarios":"Feeding non-MessagePack bytes (text, JSON, other binary); a truncated or partially-pasted MessagePack payload; a MessagePack extension type notepack.io does not support; mismatched endianness assumptions.","commonSituations":"Wrong input type (string instead of bytes); clipboard copy missing trailing bytes; MessagePack produced by a serializer using extensions notepack.io cannot decode; version skew between encoder and notepack.io.","solutions":["Confirm the input is genuinely MessagePack-encoded (magic byte 0x80-0x9f / fixmap or similar markers).","Ensure the full payload is present (not truncated).","If extension types are used, decode with a library that supports them or strip/replace them.","Read the appended err to identify the specific decode failure."],"exampleFix":"// before: feeding raw JSON text\nfromMsgPack.run(new TextEncoder().encode('{\"a\":1}')) // not MessagePack\n// after: feed actual MessagePack bytes (e.g. 0x81 0xa1 0x61 0x01)\nfromMsgPack.run(msgpackBytes)","handlingStrategy":"try-catch","validationCode":"// Cheap heuristic: MessagePack payloads start with a fixmap/fixstr/fixint marker byte\nconst first = new Uint8Array(input)[0];\nif (first === undefined || (first < 0x80 || first > 0x9f) && ![0xa0,0xc0,0xc2,0xc3,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xdc,0xde].includes(first)) {\n  // probably not MessagePack; do not call fromMsgPack.run()\n}","typeGuard":"function looksLikeMessagePack(buf) {\n  const b = new Uint8Array(buf)[0];\n  return b !== undefined && (b <= 0x7f || (b >= 0x80 && b <= 0x9f) || (b >= 0xa0 && b <= 0xbf) || (b >= 0xc0 && b <= 0xff));\n}","tryCatchPattern":"try {\n  fromMsgPack.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /Could not decode MessagePack/.test(e.message)) {\n    // input is not valid MessagePack; inspect the wrapped err and the first bytes\n  } else throw e;\n}","preventionTips":["Confirm the source emits MessagePack (check the leading byte marker).","Ensure the full payload is passed (no truncation from clipboard).","Watch for MessagePack extension types notepack.io cannot decode."],"tags":["messagepack","notepack","decode","binary","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}