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

  1. Ensure the input slice is at least the engine's block size: check (inBytes.Length - inOff) >= engine.GetBlockSize() before calling ProcessBlock.
  2. Pad the final partial block with a standard padding scheme (PKCS#7/ISO 7816-4) using a padding adapter such as PaddedBufferedBlockCipher.
  3. 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.
  4. 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

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


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/5eb95e4663aef9b4. Report an issue: GitHub.