{"record":{"id":"15f2d2dcc497ed8d","repo":"gchq/CyberChef","slug":"invalid-input","errorCode":null,"errorMessage":"Invalid input","messagePattern":"Invalid input","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromBCD.mjs","lineNumber":112,"sourceCode":"\n        if (!packed) {\n            // Discard each high nibble\n            for (let i = 0; i < nibbles.length; i++) {\n                nibbles.splice(i, 1); // lgtm [js/loop-iteration-skipped-due-to-shifting]\n            }\n        }\n\n        if (signed) {\n            const sign = nibbles.pop();\n            if (sign === 13 ||\n                sign === 11) {\n                // Negative\n                output += \"-\";\n            }\n        }\n\n        nibbles.forEach(n => {\n            if (isNaN(n)) throw new OperationError(\"Invalid input\");\n            const val = encoding.indexOf(n);\n            if (val < 0) throw new OperationError(`Value ${Utils.bin(n, 4)} is not in the encoding scheme`);\n            output += val.toString();\n        });\n\n        return new BigNumber(output);\n    }\n\n}\n\nexport default FromBCD;\n","sourceCodeStart":94,"sourceCodeEnd":124,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromBCD.mjs#L94-L124","documentation":"Thrown by From BCD when a parsed nibble is NaN, i.e. parseInt(substr(i,4), 2) could not parse 4 characters as binary. This happens in Nibbles/Bytes input format when the input contains characters other than 0 and 1 (or whitespace). The check runs per nibble during value assembly.","triggerScenarios":"Input format set to 'Nibbles' or 'Bytes' but the input string contains hex digits, letters, or other non-binary characters; a nibble group like '2abc' that cannot parseInt as base 2; malformed spacing splitting into a non-4-char group.","commonSituations":"Mismatch between the selected Input format and the actual data (e.g. hex data fed as Nibbles); copy-paste introducing non-binary chars; partial/typo'd binary string.","solutions":["Set Input format to match the data: use 'Nibbles'/'Bytes' only for pure 0/1 binary strings.","For hex or raw data, switch Input format to 'Raw'.","Strip any non-binary characters before this op if the data is genuinely binary."],"exampleFix":"// before: hex data fed as Nibbles\nfromBcd.run('FFAA', ['8 4 2 1', true, false, 'Nibbles']) // parseInt('FFAA',2) -> NaN\n// after: use Raw format\nfromBcd.run('FFAA', ['8 4 2 1', true, false, 'Raw'])","handlingStrategy":"validation","validationCode":"// For Nibbles/Bytes format, ensure the string is pure binary (0/1 + whitespace) first\nif ((inputFormat === 'Nibbles' || inputFormat === 'Bytes') && !/^[01\\s]+$/.test(input)) {\n  // switch to Raw or clean the input; do not call fromBcd.run()\n}","typeGuard":"function isBinaryNibbleString(s) {\n  return /^[01\\s]+$/.test(s);\n}","tryCatchPattern":"try {\n  fromBcd.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && e.message === 'Invalid input') {\n    // input has non-binary chars for Nibbles/Bytes; switch Input format to Raw\n  } else throw e;\n}","preventionTips":["Match the Input format arg to the actual data encoding.","Use 'Raw' for hex or byte data; reserve 'Nibbles'/'Bytes' for pure binary strings.","Strip non-binary characters before feeding binary-format input."],"tags":["bcd","binary","input-format","parsing","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}