{"record":{"id":"6a82e7719dde6e7b","repo":"peass-ng/PEASS-ng","slug":"encoding-error-in-getinstance-6a82e7","errorCode":null,"errorMessage":"encoding error in GetInstance: ","messagePattern":"encoding error in GetInstance: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGraphicString.cs","lineNumber":34,"sourceCode":"         * @exception IllegalArgumentException if the object cannot be converted.\n         * @return a DerGraphicString instance, or null.\n         */\n        public static DerGraphicString GetInstance(object obj)\n        {\n            if (obj == null || obj is DerGraphicString)\n            {\n                return (DerGraphicString)obj;\n            }\n\n            if (obj is byte[])\n            {\n                try\n                {\n                    return (DerGraphicString)FromByteArray((byte[])obj);\n                }\n                catch (Exception e)\n                {\n                    throw new ArgumentException(\"encoding error in GetInstance: \" + e.ToString(), \"obj\");\n                }\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj), \"obj\");\n        }\n\n        /**\n         * return a Graphic String from a tagged object.\n         *\n         * @param obj the tagged object holding the object we want\n         * @param explicit true if the object is meant to be explicitly\n         *              tagged false otherwise.\n         * @exception IllegalArgumentException if the tagged object cannot\n         *               be converted.\n         * @return a DerGraphicString instance, or null.\n         */\n        public static DerGraphicString GetInstance(Asn1TaggedObject obj, bool isExplicit)\n        {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGraphicString.cs#L16-L52","documentation":"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.","triggerScenarios":"Calling DerGraphicString.GetInstance(object) with a byte[] whose contents fail ASN.1 parsing in FromByteArray (malformed DER, truncated data, wrong tag).","commonSituations":"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.","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"],"exampleFix":"// before\nvar s = DerGraphicString.GetInstance(rawBytes);\n// after\nAsn1Object o;\nif (!Asn1Object.TryGetFromByteArray(rawBytes, out o) || !(o is DerGraphicString))\n    throw new InvalidDataException(\"not a DER GraphicString\");\nvar s = (DerGraphicString)o;","handlingStrategy":"validation","validationCode":"bool IsValidDerGraphicString(byte[] data) {\n    if (data == null || data.Length == 0) return false;\n    try { return Asn1Object.FromByteArray(data) is DerGraphicString; }\n    catch { return false; }\n}","typeGuard":"bool IsDerGraphicString(object o) => o is byte[] || o is DerGraphicString || o is Asn1TaggedObject;","tryCatchPattern":"try { var s = DerGraphicString.GetInstance(obj); }\ncatch (ArgumentException ex) { logger.Warn(ex, \"GraphicString decode failed\"); }","preventionTips":["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"],"tags":["csharp","asn1","bouncycastle","decoding"],"backgroundTag":"asn1-decode-failed","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}