{"record":{"id":"9ac2cd90c2520929","repo":"peass-ng/PEASS-ng","slug":"unexpected-end-of-contents-marker","errorCode":null,"errorMessage":"unexpected end-of-contents marker","messagePattern":"unexpected end-of-contents marker","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs","lineNumber":169,"sourceCode":"        internal virtual DerSequence CreateDerSequence(\n            DefiniteLengthInputStream dIn)\n        {\n            return DerSequence.FromVector(ReadVector(dIn));\n        }\n\n        internal virtual DerSet CreateDerSet(\n            DefiniteLengthInputStream dIn)\n        {\n            return DerSet.FromVector(ReadVector(dIn), false);\n        }\n\n        public Asn1Object ReadObject()\n        {\n            int tag = ReadByte();\n            if (tag <= 0)\n            {\n                if (tag == 0)\n                    throw new IOException(\"unexpected end-of-contents marker\");\n\n                return null;\n            }\n\n            //\n            // calculate tag number\n            //\n            int tagNo = ReadTagNumber(this.s, tag);\n\n            bool isConstructed = (tag & Asn1Tags.Constructed) != 0;\n\n            //\n            // calculate length\n            //\n            int length = ReadLength(this.s, limit, false);\n\n            if (length < 0) // indefinite-length method\n            {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs#L151-L187","documentation":"Asn1InputStream.ReadObject throws this IOException when the first byte of an expected ASN.1 object is 0x00, which in BER/DER is the end-of-contents (EOC) marker for indefinite-length constructions, not a valid object tag. It signals the stream's structure does not match what the caller expects — usually an extra or misplaced EOC byte.","triggerScenarios":"ReadObject is called on a stream positioned at a 0x00 byte — typically after an indefinite-length object's content was fully consumed but the caller calls ReadObject again, or the byte offset into the buffer is wrong by one (parsing trailing padding/EOC bytes as a new object).","commonSituations":"Calling ReadObject in a loop over a BER stream containing indefinite-length encoded data whose EOC terminator is then read as a top-level object; hand-slicing a byte array with a wrong offset; parsing data with trailing zero padding.","solutions":["Stop looping when ReadObject returns null (it signals end-of-data after an EOC) instead of expecting an exception-free loop to a fixed count.","Check the stream/offset alignment — you are likely positioned at an EOC marker byte (0x00) that belongs to an enclosing indefinite-length structure.","If indefinite-length BER is expected, use Asn1StreamParser instead of Asn1InputStream, which handles EOC markers correctly.","Trim trailing zero padding from the input before parsing."],"exampleFix":"// before\nwhile (true) { Asn1Object o = stream.ReadObject(); Process(o); }\n// after\nAsn1Object o;\nwhile ((o = stream.ReadObject()) != null) { Process(o); } // null on EOC/end","handlingStrategy":"validation","validationCode":"static IEnumerable<Asn1Object> ReadAll(Asn1InputStream s)\n{\n    Asn1Object o;\n    while ((o = s.ReadObject()) != null) // null = EOC/end, never loop past it\n        yield return o;\n}\n// also trim trailing zero padding:\n// while (data.Length > 0 && data[data.Length-1] == 0) Array.Resize(ref data, data.Length-1);","typeGuard":null,"tryCatchPattern":"try {\n    Asn1Object obj = stream.ReadObject();\n} catch (IOException ex) when (ex.Message == \"unexpected end-of-contents marker\") {\n    // stream positioned at an EOC byte: adjust offset or stop parsing\n    return null;\n}","preventionTips":["Treat a null return from ReadObject as normal end-of-stream, not an error to retry past","Use Asn1StreamParser instead of Asn1InputStream when indefinite-length BER is expected","Do not hand-slice byte arrays by guessed offsets — parse from the enclosing object instead","Strip trailing zero padding before constructing the input stream"],"tags":["asn1","bouncycastle","parsing","ber","stream"],"backgroundTag":"malformed-asn1-data","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}