peass-ng/PEASS-ng · error · ArgumentException
encoding error in GetInstance:
Error message
encoding error in GetInstance:
What it means
DerGraphicString.GetInstance() attempts to cast/decode the supplied object into a DerGraphicString. When the object is a byte[] but the ASN.1 decoding inside FromByteArray fails, the library wraps the original exception in an ArgumentException with the 'encoding error in GetInstance' prefix. This signals the bytes are not a valid DER-encoded GraphicString.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGraphicString.cs:34
* @exception IllegalArgumentException if the object cannot be converted.
* @return a DerGraphicString instance, or null.
*/
public static DerGraphicString GetInstance(object obj)
{
if (obj == null || obj is DerGraphicString)
{
return (DerGraphicString)obj;
}
if (obj is byte[])
{
try
{
return (DerGraphicString)FromByteArray((byte[])obj);
}
catch (Exception e)
{
throw new ArgumentException("encoding error in GetInstance: " + e.ToString(), "obj");
}
}
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
}
/**
* return a Graphic String from a tagged object.
*
* @param obj the tagged object holding the object we want
* @param explicit true if the object is meant to be explicitly
* tagged false otherwise.
* @exception IllegalArgumentException if the tagged object cannot
* be converted.
* @return a DerGraphicString instance, or null.
*/
public static DerGraphicString GetInstance(Asn1TaggedObject obj, bool isExplicit)
{View on GitHub (pinned to 53fb989abc)
Solutions
- Verify the byte[] contains a valid DER-encoded value for tag GraphicString before calling GetInstance
- Use Asn1Object.FromByteArray first and check the resulting object type before casting
- Confirm the byte slice boundaries (offset/length) are correct and the buffer is not truncated
- Catch ArgumentException and log the inner exception's ToString() for the underlying decode failure
Example fix
// before
var s = DerGraphicString.GetInstance(rawBytes);
// after
Asn1Object o;
if (!Asn1Object.TryGetFromByteArray(rawBytes, out o) || !(o is DerGraphicString))
throw new InvalidDataException("not a DER GraphicString");
var s = (DerGraphicString)o; Defensive patterns
Strategy: validation
Validate before calling
bool IsValidDerGraphicString(byte[] data) {
if (data == null || data.Length == 0) return false;
try { return Asn1Object.FromByteArray(data) is DerGraphicString; }
catch { return false; }
} Type guard
bool IsDerGraphicString(object o) => o is byte[] || o is DerGraphicString || o is Asn1TaggedObject;
Try / catch
try { var s = DerGraphicString.GetInstance(obj); }
catch (ArgumentException ex) { logger.Warn(ex, "GraphicString decode failed"); } Prevention
- Validate DER input with Asn1Object.TryGetFromByteArray before GetInstance
- Log the inner exception for decode failures
- Slice ASN.1 buffers using parsed lengths, not fixed offsets
When it happens
Trigger: Calling DerGraphicString.GetInstance(object) with a byte[] whose contents fail ASN.1 parsing in FromByteArray (malformed DER, truncated data, wrong tag).
Common situations: Decoding raw bytes pulled from certificates, CRLs, or protocol fields where the buffer is corrupted, truncated, or not actually a DER GraphicString; off-by-one slicing of ASN.1 streams.
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/6a82e7719dde6e7b.
Report an issue: GitHub.