peass-ng/PEASS-ng · error · InvalidOperationException
invalid encoding value
Error message
invalid encoding value
What it means
The DER External encoding field's tag number selects the encoding type: 0 = single-ASN1-type, 1 = octet-aligned, 2 = arbitrary. The constructor validates TagNo after reading it, and throws InvalidOperationException if it falls outside 0-2, meaning the tagged object uses a tag number undefined for External encodings.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerExternal.cs:55
{
dataValueDescriptor = enc;
offset++;
enc = GetObjFromVector(vector, offset);
}
if (vector.Count != offset + 1)
throw new ArgumentException("input vector too large", "vector");
if (!(enc is Asn1TaggedObject))
throw new ArgumentException("No tagged object found in vector. Structure doesn't seem to be of type External", "vector");
Asn1TaggedObject obj = (Asn1TaggedObject)enc;
// Use property accessor to include check on value
Encoding = obj.TagNo;
if (encoding < 0 || encoding > 2)
throw new InvalidOperationException("invalid encoding value");
externalContent = obj.GetObject();
}
/**
* Creates a new instance of DerExternal
* See X.690 for more informations about the meaning of these parameters
* @param directReference The direct reference or <code>null</code> if not set.
* @param indirectReference The indirect reference or <code>null</code> if not set.
* @param dataValueDescriptor The data value descriptor or <code>null</code> if not set.
* @param externalData The external data in its encoded form.
*/
public DerExternal(DerObjectIdentifier directReference, DerInteger indirectReference, Asn1Object dataValueDescriptor, DerTaggedObject externalData)
: this(directReference, indirectReference, dataValueDescriptor, externalData.TagNo, externalData.ToAsn1Object())
{
}
/**View on GitHub (pinned to 53fb989abc)
Solutions
- Use TagNo 0, 1, or 2 on the tagged encoding object (explicit tagging) before constructing DerExternal
- If parsing input data, treat this as malformed BER and reject/re-fetch the data
- For custom content, wrap it correctly: new DerTaggedObject(true, 0, content) rather than an arbitrary tag
Example fix
// before var bad = new DerTaggedObject(true, 5, content); // TagNo 5 var ext = new DerExternal(vector); // after var good = new DerTaggedObject(true, 0, content); // valid encoding tag var ext = new DerExternal(vector);
Defensive patterns
Strategy: validation
Validate before calling
var tag = ((Asn1TaggedObject)vector[vector.Count - 1]).TagNo;
if (tag < 0 || tag > 2)
throw new FormatException($"External encoding tag {tag} out of range 0-2");
var ext = new DerExternal(vector); Type guard
static bool IsValidEncodingTag(Asn1TaggedObject o) => o.TagNo >= 0 && o.TagNo <= 2;
Try / catch
try { var ext = new DerExternal(vector); }
catch (InvalidOperationException ex) when (ex.Message == "invalid encoding value") {
// tagged encoding uses an unsupported tag number
} Prevention
- Only use tag numbers 0, 1, or 2 for the External encoding field
- Map application encodings to the standard three External encoding choices
- Reject non-standard BER data at parse time instead of passing it into DerExternal
When it happens
Trigger: Constructing DerExternal from a vector whose final Asn1TaggedObject has TagNo < 0 or > 2.
Common situations: Decoding BER data with a non-standard or application-specific tag used where an External encoding tag is expected; hand-built tagged objects with the wrong tag number; protocol implementations that mis-encode the External content.
Related errors
- malformed object
- must be in the range 0 to 7
- if 'data' is empty, 'padBits' must be 0
- ENUMERATED has zero length
- input vector too large
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/ce6511a2aa874d0f.
Report an issue: GitHub.