{"record":{"id":"2e6032c5bf417a75","repo":"gchq/CyberChef","slug":"invalid-value","errorCode":null,"errorMessage":"Invalid value","messagePattern":"Invalid value","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/Base92.mjs","lineNumber":19,"sourceCode":"/**\n * Base92 resources.\n *\n * @author sg5506844 [sg5506844@gmail.com]\n * @copyright Crown Copyright 2021\n * @license Apache-2.0\n */\n\nimport OperationError from \"../errors/OperationError.mjs\";\n\n/**\n * Base92 alphabet char\n *\n * @param {number} val\n * @returns {number}\n */\nexport function base92Chr(val) {\n    if (val < 0 || val >= 91) {\n        throw new OperationError(\"Invalid value\");\n    }\n    if (val === 0)\n        return \"!\".charCodeAt(0);\n    else if (val <= 61)\n        return \"#\".charCodeAt(0) + val - 1;\n    else\n        return \"a\".charCodeAt(0) + val - 62;\n}\n\n/**\n * Base92 alphabet ord\n *\n * @param {string} val\n * @returns {number}\n */\nexport function base92Ord(val) {\n    if (val === \"!\")\n        return 0;","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Base92.mjs#L1-L37","documentation":"Thrown by base92Chr(val) in src/core/lib/Base92.mjs:19 when the numeric value passed in is outside the half-open range [0, 91). Base92's alphabet (as defined here) maps values 0..90 to characters: 0->'!', 1..61->'#'..'_', 62..90->'a'..'}'. A value below 0 or >= 91 has no corresponding character and indicates a bug in the caller or an upstream arithmetic overflow.","triggerScenarios":"Direct call base92Chr(-1), base92Chr(91), base92Chr(100). Indirectly: the Base92 encoder computing a digit >= 91 from malformed input, e.g. a bit-packing routine that produced an out-of-range 7-bit value because the input byte array was corrupted or the encoder's accumulator logic was bypassed.","commonSituations":"Calling base92Chr directly with an unchecked loop index; a forked or hand-rolled Base92 encoder that mis-computes digit boundaries; feeding non-byte-array data (e.g. negative numbers from a signed-int source) into the encoder path.","solutions":["Range-check val before calling: if (val >= 0 && val < 91) base92Chr(val).","Audit the caller's bit-packing math; valid Base92 digits are strictly 0..90.","Use the project's higher-level Base92 encode operation instead of the low-level helper.","If you see this from the standard operation, the input was not a clean byte array — normalize it first."],"exampleFix":"// before - unchecked value\nconst ch = base92Chr(maybeNegativeOrLarge);\n\n// after - guard the range\nconst ch = (maybeNegativeOrLarge >= 0 && maybeNegativeOrLarge < 91)\n  ? base92Chr(maybeNegativeOrLarge)\n  : null; // or throw your own error","handlingStrategy":"type-guard","validationCode":"function safeBase92Chr(val) {\n  if (typeof val !== 'number' || !Number.isInteger(val) || val < 0 || val >= 91) {\n    throw new RangeError(`base92 digit out of range: ${val}`);\n  }\n  return base92Chr(val);\n}","typeGuard":"function isValidBase92Digit(val) {\n  return typeof val === 'number' && Number.isInteger(val) && val >= 0 && val < 91;\n}","tryCatchPattern":"try {\n  const code = base92Chr(digit);\n} catch (e) {\n  if (e instanceof OperationError && e.message === 'Invalid value') {\n    // digit out of [0,91); fix upstream bit-packing\n  }\n}","preventionTips":["Prefer the high-level Base92 encode operation over calling base92Chr directly.","Range-check any computed digit before mapping to a character.","Ensure the input to the encoder is a byte array of values 0-255."],"tags":["base92","encoding","range-error","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}