peass-ng/PEASS-ng · error · ArgumentNullException
data
Error message
data
What it means
DerBitString's constructor validates its inputs and throws ArgumentNullException when the data byte array is null. BouncyCastle ASN.1 types are immutable value objects, so a null payload is never acceptable; the library fails fast at construction rather than producing a corrupt encoded BIT STRING.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs:77
if (isExplicit || o is DerBitString)
{
return GetInstance(o);
}
return FromAsn1Octets(((Asn1OctetString)o).GetOctets());
}
/**
* @param data the octets making up the bit string.
* @param padBits the number of extra bits at the end of the string.
*/
public DerBitString(
byte[] data,
int padBits)
{
if (data == null)
throw new ArgumentNullException("data");
if (padBits < 0 || padBits > 7)
throw new ArgumentException("must be in the range 0 to 7", "padBits");
if (data.Length == 0 && padBits != 0)
throw new ArgumentException("if 'data' is empty, 'padBits' must be 0");
this.mData = Arrays.Clone(data);
this.mPadBits = padBits;
}
public DerBitString(
byte[] data)
: this(data, 0)
{
}
public DerBitString(
int namedBits)
{View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure the byte[] passed to DerBitString is non-null before constructing; initialize or load it first.
- Check the upstream call that produced the array (file read, decode, P/Invoke) and handle its null/failure return.
- If null legitimately means 'no value', skip creating the DerBitString instead of constructing one.
Example fix
// before
var bs = new DerBitString(GetRawBits(), 0); // GetRawBits() may return null
// after
byte[] raw = GetRawBits();
if (raw == null) throw new InvalidOperationException("no bit string material loaded");
var bs = new DerBitString(raw, 0); Defensive patterns
Strategy: try-catch
Validate before calling
if (data == null) throw new InvalidOperationException("BIT STRING data not loaded"); Type guard
static bool IsUsableBitStringData(byte[] d) => d != null;
Try / catch
try { var bs = new DerBitString(data, padBits); }
catch (ArgumentNullException) { /* data was null: fix loading path */ } Prevention
- Never pass nullable byte[] straight into ASN.1 constructors; null-coalesce or early-return
- Assert non-null inputs in unit tests for encode helpers
- Let the library encode from strings/objects instead of raw byte arrays when possible
When it happens
Trigger: Calling new DerBitString(null, padBits) (or passing a null byte[] from a helper that failed to load key/certificate material) directly to the DerBitString(byte[], int) constructor.
Common situations: Parsing X.509 keys or certificates where a preceding decode step silently returned null; refactoring code that used to pass a populated buffer but now passes an uninitialized array.
Related errors
- str
- 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/046d2211d1b74c47.
Report an issue: GitHub.