peass-ng/PEASS-ng · error · DataLengthException
Input buffer too short
Error message
Input buffer too short
What it means
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.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs:295
public virtual int GetBlockSize()
{
return blocksizeBytes;
}
public virtual void Reset()
{
}
public virtual int ProcessBlock(byte[] inBytes, int inOff, byte[] outBytes, int outOff)
{
if ((outOff + blocksizeBytes) > outBytes.Length)
{
throw new DataLengthException("Output buffer too short");
}
if ((inOff + blocksizeBytes) > inBytes.Length)
{
throw new DataLengthException("Input buffer too short");
}
for (int i = 0; i < blocksizeBytes; i += 8)
{
currentBlock[i >> 3] = BytesToWord(inBytes, inOff + i);
}
ProcessBlock(this.currentBlock, this.currentBlock);
for (int i = 0; i < blocksizeBytes; i += 8)
{
WordToBytes(this.currentBlock[i >> 3], outBytes, outOff + i);
}
return blocksizeBytes;
}
/// <summary>
/// Process a block of data represented as 64 bit words.
/// </summary>View on GitHub (pinned to 53fb989abc)
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.
Example fix
// before
engine.ProcessBlock(data, offset, output, 0); // throws when fewer than 32 bytes remain
// after
if (data.Length - offset >= engine.GetBlockSize())
{
engine.ProcessBlock(data, offset, output, 0);
} Defensive patterns
Strategy: validation
Validate before calling
// C#
if (inBytes == null || (inBytes.Length - inOff) < engine.GetBlockSize())
throw new ArgumentException($"Input must contain at least {engine.GetBlockSize()} bytes at offset {inOff}"); Type guard
bool HasFullInputBlock(byte[] buf, int off, IBlockCipher engine) => buf != null && off >= 0 && (buf.Length - off) >= engine.GetBlockSize();
Try / catch
try
{
engine.ProcessBlock(input, inOff, output, outOff);
}
catch (DataLengthException ex) when (ex.Message == "Input buffer too short")
{
// pad final partial block or reject input; do not retry blindly
throw new CryptographyException("Input is not a full Threefish block", ex);
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid blocksize - Threefish is defined with block size of
- Invalid parameter passed to Threefish init -
- Threefish key must be same size as block (
- Threefish tweak must be bytes
- Tweak must be words.
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/5eb95e4663aef9b4.
Report an issue: GitHub.