{"record":{"id":"b0d5eb37ef4dec44","repo":"gchq/CyberChef","slug":"no-padding-requested-but-input-is-not-a-blocksiz-b0d5eb","errorCode":null,"errorMessage":"No padding requested but input is not a ${blockSize}-byte multiple.","messagePattern":"No padding requested but input is not a (.+?)-byte multiple\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/RC6.mjs","lineNumber":358,"sourceCode":" * @param {number} blockSize - Block size in bytes\n * @returns {number[]} - Padded message\n */\nfunction applyPadding(message, padding, blockSize) {\n    const remainder = message.length % blockSize;\n    let nPadding = remainder === 0 ? 0 : blockSize - remainder;\n\n    // For PKCS5, always add at least one byte (full block if already aligned)\n    if (padding === \"PKCS5\" && remainder === 0) {\n        nPadding = blockSize;\n    }\n\n    if (nPadding === 0) return [...message];\n\n    const paddedMessage = [...message];\n\n    switch (padding) {\n        case \"NO\":\n            throw new OperationError(`No padding requested but input is not a ${blockSize}-byte multiple.`);\n\n        case \"PKCS5\":\n            for (let i = 0; i < nPadding; i++) {\n                paddedMessage.push(nPadding);\n            }\n            break;\n\n        case \"ZERO\":\n            for (let i = 0; i < nPadding; i++) {\n                paddedMessage.push(0);\n            }\n            break;\n\n        case \"RANDOM\":\n            for (let i = 0; i < nPadding; i++) {\n                paddedMessage.push(Math.floor(Math.random() * 256));\n            }\n            break;","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/RC6.mjs#L340-L376","documentation":"Thrown by RC6.applyPadding when padding is 'NO' but the message length is not a multiple of the block size (blockSize = w/8, 16 bytes for the default w=32). ECB/CBC require block-aligned input; with 'NO' padding and misaligned data there is nothing valid the cipher can do.","triggerScenarios":"Calling encryptRC6(message, key, iv, 'ECB'|'CBC', 'NO', ...) with a message whose length % blockSize != 0. Stream modes (CFB/OFB/CTR) bypass padding and never hit this.","commonSituations":"Selecting 'No padding' in the UI for an input that isn't already block-aligned; binary payload of arbitrary length fed to ECB/CBC; assuming the cipher will pad when padding is explicitly 'NO'.","solutions":["Choose 'PKCS5' (or another padding) for ECB/CBC with arbitrary-length input.","Pre-pad/pre-trim the message to an exact blockSize multiple before using 'NO'.","Switch to a stream mode (CFB/OFB/CTR) if you truly want no padding."],"exampleFix":"// before\nencryptRC6(arbitraryLengthMsg, key, iv, 'CBC', 'NO');\n// after\nencryptRC6(arbitraryLengthMsg, key, iv, 'CBC', 'PKCS5');","handlingStrategy":"validation","validationCode":"const blockSize = w / 8; // 16 for default w=32\nif (padding === 'NO' && message.length % blockSize !== 0) {\n  throw new Error(`Message (${message.length}B) is not a multiple of ${blockSize}B; choose a padding scheme.`);\n}\nencryptRC6(message, key, iv, mode, padding, rounds, w);","typeGuard":null,"tryCatchPattern":"try {\n  return encryptRC6(message, key, iv, mode, 'NO', rounds, w);\n} catch (e) {\n  if (e instanceof OperationError && /No padding requested/.test(e.message)) {\n    return encryptRC6(message, key, iv, mode, 'PKCS5', rounds, w);\n  }\n  throw e;\n}","preventionTips":["Use 'PKCS5' for arbitrary-length ECB/CBC input.","Pre-align messages to blockSize when you truly need 'NO' padding.","Prefer stream modes (CFB/OFB/CTR) for unaligned data with no padding."],"tags":["crypto","rc6","padding","block-cipher","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}