{"record":{"id":"94c879591fb543cf","repo":"gchq/CyberChef","slug":"invalid-bech32-string-data-part-is-too-short-min","errorCode":null,"errorMessage":"Invalid Bech32 string: data part is too short (minimum 6 characters for checksum).","messagePattern":"Invalid Bech32 string: data part is too short \\(minimum 6 characters for checksum\\)\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/Bech32.mjs","lineNumber":268,"sourceCode":"    if (hasUpper && hasLower) {\n        throw new OperationError(\"Invalid Bech32 string: mixed case is not allowed. Use all uppercase or all lowercase.\");\n    }\n\n    // Convert to lowercase for processing\n    str = str.toLowerCase();\n\n    // Find separator (last occurrence of '1')\n    const sepIndex = str.lastIndexOf(\"1\");\n    if (sepIndex === -1) {\n        throw new OperationError(\"Invalid Bech32 string: no separator '1' found.\");\n    }\n\n    if (sepIndex === 0) {\n        throw new OperationError(\"Invalid Bech32 string: Human-Readable Part (HRP) cannot be empty.\");\n    }\n\n    if (sepIndex + 7 > str.length) {\n        throw new OperationError(\"Invalid Bech32 string: data part is too short (minimum 6 characters for checksum).\");\n    }\n\n    // Extract HRP and data part\n    const hrp = str.substring(0, sepIndex);\n    const dataPart = str.substring(sepIndex + 1);\n\n    // Validate HRP characters\n    for (let i = 0; i < hrp.length; i++) {\n        const c = hrp.charCodeAt(i);\n        if (c < 33 || c > 126) {\n            throw new OperationError(`HRP contains invalid character at position ${i}.`);\n        }\n    }\n\n    // Decode data characters to 5-bit values\n    const data = [];\n    for (let i = 0; i < dataPart.length; i++) {\n        const c = dataPart[i];","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Bech32.mjs#L250-L286","documentation":"Thrown by decode() in src/core/lib/Bech32.mjs:268 when, after the separator, fewer than 6 characters remain (sepIndex + 7 > str.length). Bech32/Bech32m always appends exactly 6 checksum characters after the data, so the data part (data + checksum) must be at least 6 characters long; anything shorter cannot carry a valid checksum.","triggerScenarios":"decode('bc1') (sepIndex=2, str.length=3, 2+7=9 > 3), decode('bc1ab') (only 2 chars after separator, < 6). Any input where the substring after the last '1' is shorter than 6 characters.","commonSituations":"Truncated address missing the checksum; a string that ends right at or just after the separator; user typed only the HRP and separator; copy-paste that cut off the tail.","solutions":["Verify the address is complete — the part after '1' must be at least 6 characters (checksum) plus any data words.","Re-copy the full address from its source.","Add a length pre-check: if (str.lastIndexOf('1') + 7 > str.length) warn the user.","For SegWit addresses, expect at least HRP + '1' + version + program words + 6 checksum chars."],"exampleFix":"// before - checksum truncated\ndecode('bc1q'); // too short after separator\n\n// after - full address with checksum\ndecode('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq'); // 39 chars after '1'","handlingStrategy":"validation","validationCode":"function hasEnoughDataAfterSeparator(str) {\n  const sep = str.lastIndexOf('1');\n  return sep !== -1 && sep + 7 <= str.length;\n}","typeGuard":"function isLongEnoughBech32(s) {\n  if (typeof s !== 'string') return false;\n  const i = s.lastIndexOf('1');\n  return i !== -1 && i + 7 <= s.length;\n}","tryCatchPattern":"try {\n  decode(input);\n} catch (e) {\n  if (e instanceof OperationError && /data part is too short/.test(e.message)) {\n    // address is truncated; ask the user to re-copy\n  }\n}","preventionTips":["Expect at least HRP + '1' + 6 checksum chars for any valid Bech32 string.","Reject obviously short input at the UI before decoding.","Treat checksum-too-short errors as truncation and re-acquire the source."],"tags":["bech32","decoding","checksum","length-limit","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}