{"record":{"id":"085e71feaedd0ea1","repo":"gchq/CyberChef","slug":"encoded-string-exceeds-maximum-length-of-90-charac","errorCode":null,"errorMessage":"Encoded string exceeds maximum length of 90 characters (got ${result.length}). Consider using smaller input data.","messagePattern":"Encoded string exceeds maximum length of 90 characters \\(got (.+?)\\)\\. Consider using smaller input data\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/Bech32.mjs","lineNumber":223,"sourceCode":"        // Witness version is kept as single 5-bit value, program is converted\n        words = [witnessVersion].concat(toWords(witnessProgram));\n    } else {\n        // Generic encoding: convert all bytes to 5-bit words\n        words = toWords(data);\n    }\n\n    // Create checksum\n    const checksum = createChecksum(hrpLower, words, encoding);\n\n    // Build result string\n    let result = hrpLower + \"1\";\n    for (const w of words.concat(checksum)) {\n        result += CHARSET[w];\n    }\n\n    // Check maximum length (90 characters)\n    if (result.length > 90) {\n        throw new OperationError(`Encoded string exceeds maximum length of 90 characters (got ${result.length}). Consider using smaller input data.`);\n    }\n\n    return result;\n}\n\n/**\n * Decode a Bech32/Bech32m string\n *\n * @param {string} str - Bech32/Bech32m encoded string\n * @param {string} encoding - \"Bech32\", \"Bech32m\", or \"Auto-detect\"\n * @returns {{hrp: string, data: number[]}} - Decoded HRP and data bytes\n */\nexport function decode(str, encoding = \"Auto-detect\") {\n    // Check for empty input\n    if (!str || str.length === 0) {\n        throw new OperationError(\"Input cannot be empty.\");\n    }\n","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Bech32.mjs#L205-L241","documentation":"Thrown by encode() in src/core/lib/Bech32.mjs:223 after building the result string if its total length exceeds 90 characters. BIP-0173 caps the entire Bech32 string (HRP + separator + data + checksum) at 90 characters; longer inputs would violate the specification and risk incompatibility across parsers. This is a final guard, checked after the checksum is appended.","triggerScenarios":"encode(hrp, largeData, ...) where hrp.length + 1 + ceil(data.length*8/5) + 6 > 90. For example, a long HRP combined with a 40-byte program, or generic (non-segwit) encoding of a >50-byte payload.","commonSituations":"Encoding arbitrary large data (not a Bitcoin address) into Bech32 and hitting the spec limit; very long HRP chosen by the caller; trying to embed a full transaction or message in a single Bech32 string instead of chunking.","solutions":["Reduce the input data length so the final string is <= 90 characters.","Use a shorter HRP.","Split large payloads across multiple Bech32 strings if the use case allows.","If you need arbitrary-length Base32-like encoding without the 90-char cap, use a different scheme (e.g. raw Base32)."],"exampleFix":"// before - payload too large for one Bech32 string\nencode('bb', hugeByteArray, 'Bech32', false);\n\n// after - chunk the payload\nconst chunks = chunkBytes(hugeByteArray, maxBytesForLimit);\nconst encoded = chunks.map(c => encode('bb', c, 'Bech32', false));","handlingStrategy":"validation","validationCode":"function estimateBech32Length(hrp, dataLen, segwit) {\n  const programLen = segwit ? dataLen - 1 : dataLen;\n  const wordCount = Math.ceil((programLen * 8) / 5) + (segwit ? 1 : 0);\n  return hrp.length + 1 + wordCount + 6;\n}\n// if (estimateBech32Length(hrp, data.length, true) > 90) reject early;","typeGuard":"function fitsBech32Limit(hrp, data, segwit) {\n  return estimateBech32Length(hrp, data.length, segwit) <= 90;\n}","tryCatchPattern":"try {\n  encode(hrp, data, 'Bech32', segwit);\n} catch (e) {\n  if (e instanceof OperationError && /exceeds maximum length of 90/.test(e.message)) {\n    // split payload or shorten HRP\n  }\n}","preventionTips":["Bech32 is for short identifiers (addresses), not bulk data encoding.","Estimate the final length before encoding and reject oversized payloads.","Use a shorter HRP or chunk large data across multiple strings."],"tags":["bech32","encoding","bip-0173","length-limit","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}