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
- Size the output buffer to at least off+len for the operation (use GetOutputSize/GetUpdateOutputSize where available)
- Check off and len values passed to the API against buf.Length
- 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
- Size output buffers via GetOutputSize/GetUpdateOutputSize
- Assert off+len <= buf.Length before calling crypto APIs
- Avoid placeholder message strings like 'msg' in Check calls
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
- data
- must be in the range 0 to 7
- if 'data' is empty, 'padBits' must be 0
- attempt to get non-octet aligned data from BIT STRING
- truncated BIT STRING detected
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/05d2706570202fd4.
Report an issue: GitHub.