peass-ng/PEASS-ng · error · OutputLengthException

msg

Error message

msg

What it means

Check.OutputLength validates that reading 'len' bytes at 'off' from a buffer stays in bounds; if off > buf.Length - len it throws the caller-supplied msg wrapped in an OutputLengthException (a DataLengthException subclass). The literal message 'msg' means the caller passed a placeholder/unused message string, but the real cause is an out-of-range offset/length pair on an output buffer.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/Check.cs:20

{
    internal class Check
    {
        internal static void DataLength(bool condition, string msg)
        {
            if (condition)
                throw new DataLengthException(msg);
        }

        internal static void DataLength(byte[] buf, int off, int len, string msg)
        {
            if (off > (buf.Length - len))
                throw new DataLengthException(msg);
        }

        internal static void OutputLength(byte[] buf, int off, int len, string msg)
        {
            if (off > (buf.Length - len))
                throw new OutputLengthException(msg);
        }
    }
}

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Size the output buffer to at least off+len for the operation (use GetOutputSize/GetUpdateOutputSize where available)
  2. Check off and len values passed to the API against buf.Length
  3. Replace placeholder 'msg' arguments with descriptive messages to make future failures diagnosable

Example fix

// before
byte[] out = new byte[input.Length];
cipher.DoFinal(input, 0, input.Length, out, 0);
// after
int needed = cipher.GetOutputSize(input.Length);
byte[] out = new byte[needed];
cipher.DoFinal(input, 0, input.Length, out, 0);
Defensive patterns

Strategy: validation

Validate before calling

bool OutputBufferOk(byte[] buf, int off, int len) => buf != null && off >= 0 && len >= 0 && off + len <= buf.Length;

Try / catch

try { engine.DoFinal(input, 0, input.Length, output, 0); }
catch (OutputLengthException ex) { logger.Error(ex, "output buffer too small"); throw; }

Prevention

When it happens

Trigger: Calling a cipher/mac/digest DoFinal or ProcessBytes-style API with an output buffer whose off+len exceeds the buffer length, where the library routes the check through Check.OutputLength.

Common situations: Allocating output buffers from the input size without padding, reusing undersized buffers, using wrong offsets after partial processing, hard-coded 'msg' placeholder from copy-pasted code.

Related errors


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