{"record":{"id":"4c3c0218455fc642","repo":"gchq/CyberChef","slug":"err-4c3c02","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ProtobufDecode.mjs","lineNumber":59,"sourceCode":"            {\n                name: \"Show Types\",\n                type: \"boolean\",\n                value: false\n            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {JSON}\n     */\n    run(input, args) {\n        input = new Uint8Array(input);\n        try {\n            return Protobuf.decode(input, args);\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default ProtobufDecode;\n","sourceCodeStart":41,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ProtobufDecode.mjs#L41-L66","documentation":"Protobuf Decode delegates to Protobuf.decode and wraps any thrown error in an OperationError, surfacing the underlying message as ${err}. Decode failures arise from malformed/truncated protobuf wire data, an invalid or unparseable .proto schema, schema/data mismatches, or invalid varint/wire-type sequences. The wrapper converts internal library errors into CyberChef's expected OperationError output channel.","triggerScenarios":"Decoding non-protobuf bytes; a truncated message missing field data; a .proto schema with syntax errors; a wire type the decoder cannot handle (e.g. malformed length-delimited or group fields); oversized/recursive input that hits the decoder's internal limits.","commonSituations":"Pointing the op at random binary; feeding a gRPC frame including the 5-byte prefix; schema that does not match the producing schema; partial reads from a stream.","solutions":["Confirm the input is real protobuf wire data (field tag + wire-type varints).","If using a schema, validate the .proto syntax with protoc first.","Strip any gRPC/framing prefix (length + compressed flag) before decoding.","Read the wrapped ${err} text — it usually names the exact decode problem (truncated varint, bad wire type, unknown enum, etc.)."],"exampleFix":"// before: gRPC-framed bytes\nrun(grpcFrameBuf, [\"\", false, false]);\n\n// after: protobuf payload only (prefix stripped)\nrun(pbPayloadBuf, [schema, false, false]);","handlingStrategy":"try-catch","validationCode":"// Best-effort shape check before decoding: protobuf wire bytes are a sequence of\n// (field_number << 3 | wire_type) varints with wire_type in 0..5.\nfunction looksLikeProtobuf(buf) {\n  const u = new Uint8Array(buf);\n  return u.length > 0 && (u[0] & 0x07) <= 5;\n}","typeGuard":"function isLikelyProtobuf(buf) {\n  const u = new Uint8Array(buf);\n  return u.length > 0 && (u[0] & 0x07) <= 5;\n}","tryCatchPattern":"try {\n  return protobufDecode.run(input, [schema, showUnknown, showTypes]);\n} catch (e) {\n  // e.message is the wrapped Protobuf.decode error; surface it to the user\n  throw e;\n}","preventionTips":["Validate the .proto schema with protoc before use.","Strip gRPC/framing prefixes before decoding.","Inspect the wrapped message — it names the exact decode problem."],"tags":["protobuf","parsing","serialization","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}