{"record":{"id":"5eb95e4663aef9b4","repo":"peass-ng/PEASS-ng","slug":"input-buffer-too-short","errorCode":null,"errorMessage":"Input buffer too short","messagePattern":"Input buffer too short","errorType":"exception","errorClass":"DataLengthException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs","lineNumber":295,"sourceCode":"\t\tpublic virtual int GetBlockSize()\n\t\t{\n\t\t\treturn blocksizeBytes;\n\t\t}\n\n\t\tpublic virtual void Reset()\n\t\t{\n\t\t}\n\n\t\tpublic virtual int ProcessBlock(byte[] inBytes, int inOff, byte[] outBytes, int outOff)\n\t\t{\n\t\t\tif ((outOff + blocksizeBytes) > outBytes.Length)\n\t\t\t{\n\t\t\t\tthrow new DataLengthException(\"Output buffer too short\");\n\t\t\t}\n\n\t\t\tif ((inOff + blocksizeBytes) > inBytes.Length)\n\t\t\t{\n\t\t\t\tthrow new DataLengthException(\"Input buffer too short\");\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < blocksizeBytes; i += 8)\n\t\t\t{\n\t\t\t\tcurrentBlock[i >> 3] = BytesToWord(inBytes, inOff + i);\n\t\t\t}\n\t\t\tProcessBlock(this.currentBlock, this.currentBlock);\n\t\t\tfor (int i = 0; i < blocksizeBytes; i += 8)\n\t\t\t{\n\t\t\t\tWordToBytes(this.currentBlock[i >> 3], outBytes, outOff + i);\n\t\t\t}\n\n\t\t\treturn blocksizeBytes;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Process a block of data represented as 64 bit words.\n\t\t/// </summary>","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs#L277-L313","documentation":"ThreefishEngine.ProcessBlock(byte[], int, byte[], int) throws this DataLengthException when fewer than blocksizeBytes (32/64/128 for Threefish-256/512/1024) bytes are available in the input array starting at inOff. Threefish is a strict block cipher: it only operates on exactly one full block, so a short input would read past the end of the buffer. The library pre-validates buffer bounds instead of letting an IndexOutOfRangeException escape.","triggerScenarios":"Calling ProcessBlock(inBytes, inOff, outBytes, outOff) where inBytes.Length - inOff < GetBlockSize() — e.g. passing a 16-byte buffer to a Threefish-256 engine (32-byte blocks), or passing a non-zero inOff into an exactly-block-sized array.","commonSituations":"Feeding ciphertext/plaintext that was encrypted with a different block size (e.g. AES's 16 bytes into Threefish's 32); forgetting to pad the final partial block when processing a stream manually; off-by-one or leftover-offset bugs in the caller's buffer management.","solutions":["Ensure the input slice is at least the engine's block size: check (inBytes.Length - inOff) >= engine.GetBlockSize() before calling ProcessBlock.","Pad the final partial block with a standard padding scheme (PKCS#7/ISO 7816-4) using a padding adapter such as PaddedBufferedBlockCipher.","Verify you constructed the engine with the intended block size (new ThreefishEngine(256) needs 32-byte blocks) and that your data wasn't produced with a smaller block cipher.","If inOff is non-zero, confirm it points to the start of a complete block, not the tail of the array."],"exampleFix":"// before\nengine.ProcessBlock(data, offset, output, 0); // throws when fewer than 32 bytes remain\n// after\nif (data.Length - offset >= engine.GetBlockSize())\n{\n    engine.ProcessBlock(data, offset, output, 0);\n}","handlingStrategy":"validation","validationCode":"// C#\nif (inBytes == null || (inBytes.Length - inOff) < engine.GetBlockSize())\n    throw new ArgumentException($\"Input must contain at least {engine.GetBlockSize()} bytes at offset {inOff}\");","typeGuard":"bool HasFullInputBlock(byte[] buf, int off, IBlockCipher engine) => buf != null && off >= 0 && (buf.Length - off) >= engine.GetBlockSize();","tryCatchPattern":"try\n{\n    engine.ProcessBlock(input, inOff, output, outOff);\n}\ncatch (DataLengthException ex) when (ex.Message == \"Input buffer too short\")\n{\n    // pad final partial block or reject input; do not retry blindly\n    throw new CryptographyException(\"Input is not a full Threefish block\", ex);\n}","preventionTips":["Always size input buffers to exact multiples of engine.GetBlockSize() (32/64/128 bytes).","Use BufferedBlockCipher or PaddedBufferedBlockCipher instead of raw ProcessBlock for streams.","Check (buf.Length - offset) >= blockSize before every call, especially for the final block of a stream.","Confirm both ends of a protocol use the same Threefish variant (256/512/1024)."],"tags":["csharp","cryptography","buffer-size","threefish","block-cipher"],"backgroundTag":"input-buffer-too-short","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}