{"record":{"id":"1016e842d17a1906","repo":"gchq/CyberChef","slug":"err-1016e8","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/VarIntDecode.mjs","lineNumber":51,"sourceCode":"     * @param {Object[]} args\n     * @returns {number}\n     */\n    run(input, args) {\n        try {\n            if (typeof BigInt === \"function\") {\n                let result = BigInt(0);\n                let offset = BigInt(0);\n                for (let i = 0; i < input.length; i++) {\n                    result |= BigInt(input[i] & 0x7f) << offset;\n                    if (!(input[i] & 0x80)) break;\n                    offset += BigInt(7);\n                }\n                return result.toString();\n            } else {\n                return Protobuf.varIntDecode(input).toString();\n            }\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default VarIntDecode;\n","sourceCodeStart":33,"sourceCodeEnd":58,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/VarIntDecode.mjs#L33-L58","documentation":"Catch-all OperationError thrown by 'VarInt Decode' when the decode loop throws for any reason. The operation expects a byteArray input; the BigInt path reads input[i] & 0x7f per byte. Any non-numeric/NaN byte (e.g. the byteArray contains non-integer or out-of-range entries) makes the BigInt bitwise op throw, which is rewrapped here.","triggerScenarios":"Feeding input that is not a clean byteArray of integers 0-255, feeding an empty input that downstream code mishandles, or running the operation with an inputType that produced non-byte values. The catch also wraps any error from the Protobuf fallback path when BigInt is unavailable.","commonSituations":"Chaining from an operation that emits a string or non-byteArray type into VarInt Decode without a To ByteArray / From Hex step, or malformed varint streams.","solutions":["Ensure the input is a valid byteArray (run 'From Hex' or 'To ByteArray' first).","Confirm each byte is an integer in 0-255.","Inspect the wrapped err message in the OperationError for the underlying cause."],"exampleFix":"// before: feeding a hex string directly\n// after: convert to bytes first\nrecipe: [ \"From Hex\", \"VarInt Decode\" ]","handlingStrategy":"validation","validationCode":"if (!Array.isArray(input) || input.some(b => typeof b !== \"number\" || b < 0 || b > 255 || !Number.isInteger(b))) {\n  throw new Error(\"VarInt Decode expects a byteArray of integers 0-255\");\n}","typeGuard":"function isByteArray(data) { return Array.isArray(data) && data.every(b => Number.isInteger(b) && b >= 0 && b <= 255); }","tryCatchPattern":"try { return varIntDecode(input); }\ncatch (err) { throw new Error(`VarInt decode failed: ${err.message}`); }","preventionTips":["Insert a 'From Hex' / 'To ByteArray' step before VarInt Decode.","Ensure upstream operations output byteArray type."],"tags":["protobuf","varint","validation","input-type","runtime"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}