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

  1. Ensure the byte[] passed to DerBitString is non-null before constructing; initialize or load it first.
  2. Check the upstream call that produced the array (file read, decode, P/Invoke) and handle its null/failure return.
  3. 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

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


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