peass-ng/PEASS-ng · error · InvalidOperationException
malformed object
Error message
malformed object
What it means
The DerApplicationSpecific constructor that concatenates DER encodings of a vector of Asn1Encodable elements catches IOException from GetDerEncoded and rethrows InvalidOperationException 'malformed object'. An element in the vector could not produce its DER encoding.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerApplicationSpecific.cs:83
public DerApplicationSpecific(
int tagNo,
Asn1EncodableVector vec)
{
this.tag = tagNo;
this.isConstructed = true;
MemoryStream bOut = new MemoryStream();
for (int i = 0; i != vec.Count; i++)
{
try
{
byte[] bs = vec[i].GetDerEncoded();
bOut.Write(bs, 0, bs.Length);
}
catch (IOException e)
{
throw new InvalidOperationException("malformed object", e);
}
}
this.octets = bOut.ToArray();
}
private int GetLengthOfHeader(
byte[] data)
{
int length = data[1]; // TODO: assumes 1 byte tag
if (length == 0x80)
{
return 2; // indefinite-length encoding
}
if (length > 127)
{
int size = length & 0x7f;View on GitHub (pinned to 53fb989abc)
Solutions
- Validate each element encodes cleanly: call element.GetDerEncoded() in try/catch before adding to the vector
- Inspect e.InnerException for the real encoding failure
- Rebuild the offending element from verified input data
- Ensure nested objects were successfully parsed (catch earlier IOExceptions rather than letting malformed objects propagate)
Example fix
// before
var vec = new Asn1EncodableVector(maybeBrokenObj);
var app = new DerApplicationSpecific(1, vec); // throws
// after
byte[] enc;
try { enc = maybeBrokenObj.GetDerEncoded(); }
catch (IOException ex) { throw new InvalidDataException("element not encodable", ex); }
var vec = new Asn1EncodableVector(Asn1Object.FromByteArray(enc));
var app = new DerApplicationSpecific(1, vec); Defensive patterns
Strategy: try-catch
Validate before calling
// pre-verify each element is encodable
foreach (Asn1Encodable e in elements) { try { e.GetDerEncoded(); } catch (IOException) { return false; } } Try / catch
try { var app = new DerApplicationSpecific(tagNo, vec); }
catch (InvalidOperationException ex) { log.Error("element not DER-encodable", ex.InnerException); return null; } Prevention
- Test-encode nested elements before assembling application-specific structures
- Only add fully parsed, valid Asn1Objects to the vector
- Inspect InnerException to find the failing element
When it happens
Trigger: Building new DerApplicationSpecific(tagNo, Asn1EncodableVector) where one of the vector's elements throws during GetDerEncoded — e.g. an improperly initialized or recursively malformed nested object.
Common situations: Assembling application-specific structures for protocols (e.g. custom PKCS objects) with a nested object built from bad data; reusing Asn1Encodable objects after failed parsing.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- must be in the range 0 to 7
- if 'data' is empty, 'padBits' must be 0
- ENUMERATED has zero length
- input vector too large
- No tagged object found in vector. Structure doesn't seem to
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/33726a2fcef24856.
Report an issue: GitHub.