{"record":{"id":"9d3186e07efb6c17","repo":"peass-ng/PEASS-ng","slug":"cannot-recognise-object-in-stream","errorCode":null,"errorMessage":"cannot recognise object in stream","messagePattern":"cannot recognise object in stream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1Object.cs","lineNumber":46,"sourceCode":"\t\t\t{\n\t\t\t\tthrow new IOException(\"cannot recognise object in byte array\");\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>Read a base ASN.1 object from a stream.</summary>\n\t\t/// <param name=\"inStr\">The stream to parse.</param>\n\t\t/// <returns>The base ASN.1 object represented by the byte array.</returns>\n\t\t/// <exception cref=\"IOException\">If there is a problem parsing the data.</exception>\n\t\tpublic static Asn1Object FromStream(\n\t\t\tStream inStr)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn new Asn1InputStream(inStr).ReadObject();\n\t\t\t}\n\t\t\tcatch (InvalidCastException)\n\t\t\t{\n\t\t\t\tthrow new IOException(\"cannot recognise object in stream\");\n\t\t\t}\n\t\t}\n\n\t\tpublic sealed override Asn1Object ToAsn1Object()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\n\t\tinternal abstract void Encode(DerOutputStream derOut);\n\n\t\tprotected abstract bool Asn1Equals(Asn1Object asn1Object);\n\t\tprotected abstract int Asn1GetHashCode();\n\n\t\tinternal bool CallAsn1Equals(Asn1Object obj)\n\t\t{\n\t\t\treturn Asn1Equals(obj);\n\t\t}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1Object.cs#L28-L64","documentation":"Asn1Object.FromStream wraps Asn1InputStream.ReadObject and converts any InvalidCastException bubbling out of parsing into an IOException with this message. It means the stream contained bytes whose decoded ASN.1 object could not be cast to a recognized Asn1Object, i.e. the data is not a valid/complete DER or BER structure the library understands.","triggerScenarios":"Calling Asn1Object.FromStream on a stream whose first object decodes to an internal type that fails the cast to Asn1Object — typically truncated, garbage, or non-ASN.1 bytes at the start of the stream.","commonSituations":"Parsing a certificate, key file, or PKCS#7 blob that is actually base64 text, a PEM header, or raw binary that is not ASN.1; feeding a truncated DER file; passing the wrong stream (e.g. decrypted-wrong bytes after bad key derivation).","solutions":["Verify the input is genuine DER/BER (hexdump first bytes: valid SEQUENCE starts 0x30 ...)","If input is PEM, strip the -----BEGIN/END----- armor and base64-decode before FromStream","Wrap in try/catch for IOException and fail gracefully / surface a 'not valid ASN.1' message to the caller","Regenerate or re-export the file from its source; check for truncation during transfer"],"exampleFix":"// before\nAsn1Object obj = Asn1Object.FromStream(stream);\n// after\nbyte[] der = Convert.FromBase64String(pemBody); // if PEM\nusing (var ms = new MemoryStream(der))\n{\n    try { Asn1Object obj = Asn1Object.FromStream(ms); }\n    catch (IOException) { /* not valid ASN.1 data */ }\n}","handlingStrategy":"try-catch","validationCode":"// verify plausible DER header before parsing\nbyte[] head = new byte[2];\nif (stream is MemoryStream ms && ms.Length >= 2 && (ms.ToArray()[0] & 0x1f) != 0) { /* plausible */ }","typeGuard":"bool IsPlausibleDer(Stream s) { if (!s.CanRead) return false; int b = s.ReadByte(); s.Position -= 1; return b == 0x30 || b == 0x31 || (b & 0x1f) != 0 && (b & 0xc0) != 0; }","tryCatchPattern":"try { var obj = Asn1Object.FromStream(stream); }\ncatch (IOException ex) { log.Warn(\"stream is not valid ASN.1: \" + ex.Message); return null; }","preventionTips":["PEM-decode (strip armor + base64) before FromStream","Hexdump first bytes to confirm a valid ASN.1 tag","Never parse raw plaintext/ciphertext blobs as ASN.1","Catch IOException at every parse boundary and surface a clear message"],"tags":["asn1","parsing","io","bouncycastle"],"backgroundTag":"invalid-asn1-data","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}