peass-ng/PEASS-ng · error · DataLengthException

Output buffer too short

Error message

Output buffer too short

What it means

ProcessBlock verifies that the output buffer has room for one full block (blocksizeBytes) starting at outOff, throwing DataLengthException if not. The input buffer is checked immediately afterwards for the same condition.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs:290

		public virtual bool IsPartialBlockOkay
		{
			get { return false; }
		}

		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;

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Allocate outBytes with at least outOff + blocksizeBytes bytes (block size of the engine variant)
  2. Set outOff so a full block fits within the buffer
  3. Check GetBlockSize() at runtime to size buffers dynamically

Example fix

// before
byte[] output = new byte[32];
engine.ProcessBlock(input, 0, output, 0); // engine is Threefish-512
// after
byte[] output = new byte[engine.GetBlockSize()];
engine.ProcessBlock(input, 0, output, 0);
Defensive patterns

Strategy: validation

Validate before calling

int bs = engine.GetBlockSize();
if (outBytes == null || outBytes.Length - outOff < bs)
    throw new ArgumentException("Output buffer must hold at least one block (" + bs + " bytes)");
if (inBytes == null || inBytes.Length - inOff < bs)
    throw new ArgumentException("Input buffer must hold at least one block (" + bs + " bytes)");
engine.ProcessBlock(inBytes, inOff, outBytes, outOff);

Type guard

bool CanProcessBlock(ThreefishEngine e, byte[] inB, int inOff, byte[] outB, int outOff) => inB != null && outB != null && inOff + e.GetBlockSize() <= inB.Length && outOff + e.GetBlockSize() <= outB.Length;

Try / catch

try { int n = engine.ProcessBlock(in, inOff, out, outOff); }
catch (DataLengthException ex) { /* grow buffer and retry */ }

Prevention

When it happens

Trigger: Calling ProcessBlock(in, inOff, out, outOff) where outBytes.Length - outOff < blocksizeBytes (e.g. writing a 64-byte Threefish-512 block into a 32-byte buffer or near the end of a shared buffer).

Common situations: Allocating output buffer sized for a smaller Threefish variant; outOff placed too close to the end of a reusable buffer; forgetting that Threefish is unbuffered and processes exactly one block per call.

Related errors


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