{"record":{"id":"33726a2fcef24856","repo":"peass-ng/PEASS-ng","slug":"malformed-object","errorCode":null,"errorMessage":"malformed object","messagePattern":"malformed object","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerApplicationSpecific.cs","lineNumber":83,"sourceCode":"\n\t\tpublic DerApplicationSpecific(\n\t\t\tint tagNo,\n\t\t\tAsn1EncodableVector vec)\n\t\t{\n\t\t\tthis.tag = tagNo;\n\t\t\tthis.isConstructed = true;\n\t\t\tMemoryStream bOut = new MemoryStream();\n\n\t\t\tfor (int i = 0; i != vec.Count; i++)\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tbyte[] bs = vec[i].GetDerEncoded();\n\t\t\t\t\tbOut.Write(bs, 0, bs.Length);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException(\"malformed object\", e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.octets = bOut.ToArray();\n\t\t}\n\n\t\tprivate int GetLengthOfHeader(\n\t\t\tbyte[] data)\n\t\t{\n\t\t\tint length = data[1]; // TODO: assumes 1 byte tag\n\n\t\t\tif (length == 0x80)\n\t\t\t{\n\t\t\t\treturn 2;      // indefinite-length encoding\n\t\t\t}\n\n\t\t\tif (length > 127)\n\t\t\t{\n\t\t\t\tint size = length & 0x7f;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerApplicationSpecific.cs#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nvar vec = new Asn1EncodableVector(maybeBrokenObj);\nvar app = new DerApplicationSpecific(1, vec); // throws\n// after\nbyte[] enc;\ntry { enc = maybeBrokenObj.GetDerEncoded(); }\ncatch (IOException ex) { throw new InvalidDataException(\"element not encodable\", ex); }\nvar vec = new Asn1EncodableVector(Asn1Object.FromByteArray(enc));\nvar app = new DerApplicationSpecific(1, vec);","handlingStrategy":"try-catch","validationCode":"// pre-verify each element is encodable\nforeach (Asn1Encodable e in elements) { try { e.GetDerEncoded(); } catch (IOException) { return false; } }","typeGuard":null,"tryCatchPattern":"try { var app = new DerApplicationSpecific(tagNo, vec); }\ncatch (InvalidOperationException ex) { log.Error(\"element not DER-encodable\", ex.InnerException); return null; }","preventionTips":["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"],"tags":["asn1","der-encoding","bouncycastle"],"backgroundTag":"der-encoding-failed","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}