gchq/CyberChef · error · OperationError

Could not decode MessagePack to JSON: ${err}

Error message

Could not decode MessagePack to JSON: ${err}

What it means

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.

Source

Thrown at src/core/operations/FromMessagePack.mjs:41

        this.module = "Code";
        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.";
        this.infoURL = "https://wikipedia.org/wiki/MessagePack";
        this.inputType = "ArrayBuffer";
        this.outputType = "JSON";
        this.args = [];
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {JSON}
     */
    run(input, args) {
        try {
            const buf = Buffer.from(new Uint8Array(input));
            return notepack.decode(buf);
        } catch (err) {
            throw new OperationError(`Could not decode MessagePack to JSON: ${err}`);
        }
    }

}

export default FromMessagePack;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Confirm the input is genuinely MessagePack-encoded (magic byte 0x80-0x9f / fixmap or similar markers).
  2. Ensure the full payload is present (not truncated).
  3. If extension types are used, decode with a library that supports them or strip/replace them.
  4. Read the appended err to identify the specific decode failure.

Example fix

// before: feeding raw JSON text
fromMsgPack.run(new TextEncoder().encode('{"a":1}')) // not MessagePack
// after: feed actual MessagePack bytes (e.g. 0x81 0xa1 0x61 0x01)
fromMsgPack.run(msgpackBytes)
Defensive patterns

Strategy: try-catch

Validate before calling

// Cheap heuristic: MessagePack payloads start with a fixmap/fixstr/fixint marker byte
const first = new Uint8Array(input)[0];
if (first === undefined || (first < 0x80 || first > 0x9f) && ![0xa0,0xc0,0xc2,0xc3,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xdc,0xde].includes(first)) {
  // probably not MessagePack; do not call fromMsgPack.run()
}

Type guard

function looksLikeMessagePack(buf) {
  const b = new Uint8Array(buf)[0];
  return b !== undefined && (b <= 0x7f || (b >= 0x80 && b <= 0x9f) || (b >= 0xa0 && b <= 0xbf) || (b >= 0xc0 && b <= 0xff));
}

Try / catch

try {
  fromMsgPack.run(input, args);
} catch (e) {
  if (e.type === 'OperationError' && /Could not decode MessagePack/.test(e.message)) {
    // input is not valid MessagePack; inspect the wrapped err and the first bytes
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/6bc0017a73e549ed. Report an issue: GitHub.