{"record":{"id":"5cc4b26b26ef7bbf","repo":"peass-ng/PEASS-ng","slug":"eof-found-reading-length","errorCode":null,"errorMessage":"EOF found reading length","messagePattern":"EOF found reading length","errorType":"exception","errorClass":"EndOfStreamException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs","lineNumber":296,"sourceCode":"\n            if (length == 0x80)\n                return -1;      // indefinite-length encoding\n\n            if (length > 127)\n            {\n                int size = length & 0x7f;\n\n                // Note: The invalid long form \"0xff\" (see X.690 8.1.3.5c) will be caught here\n                if (size > 4)\n                    throw new IOException(\"DER length more than 4 bytes: \" + size);\n\n                length = 0;\n                for (int i = 0; i < size; i++)\n                {\n                    int next = s.ReadByte();\n\n                    if (next < 0)\n                        throw new EndOfStreamException(\"EOF found reading length\");\n\n                    length = (length << 8) + next;\n                }\n\n                if (length < 0)\n                    throw new IOException(\"corrupted stream - negative length found\");\n\n                if (length >= limit && !isParsing)   // after all we must have read at least 1 byte\n                    throw new IOException(\"corrupted stream - out of bounds length found: \" + length + \" >= \" + limit);\n            }\n\n            return length;\n        }\n\n        private static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)\n        {\n            int len = defIn.Remaining;\n            if (len >= tmpBuffers.Length)","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs#L278-L314","documentation":"ReadLength ran out of stream while reading the multi-byte long-form length octets: a byte read returned < 0 (EOF). The library throws EndOfStreamException because the declared length field is incomplete, so no valid DER object can follow.","triggerScenarios":"Stream ends in the middle of a long-form length field (first length byte 0x81-0x84 declares N length bytes but fewer than N bytes remain).","commonSituations":"Truncated certificate/PFX downloads; reading from a partially transferred network stream; passing a stream already consumed by a previous parser; cut-off log-embedded blobs.","solutions":["Verify the source data is complete (check file size, download integrity, Content-Length)","Ensure the stream position is at the true start of the ASN.1 object and not partially consumed","Re-read the blob from source; if the stream is non-seekable, buffer it fully into a byte[] first","Wrap parsing in try-catch for EndOfStreamException and treat input as corrupt"],"exampleFix":"// before\nAsn1Object o = new Asn1InputStream(networkStream).ReadObject();\n// after\nbyte[] all = ReadAllBytes(networkStream); // buffer fully first\nAsn1Object o = Asn1Object.FromByteArray(all);","handlingStrategy":"try-catch","validationCode":"static bool StreamHasEnoughBytes(Stream s, int minBytes)\n{\n    return s.CanSeek && (s.Length - s.Position) >= minBytes;\n}","typeGuard":null,"tryCatchPattern":"try { Asn1Object o = new Asn1InputStream(stream).ReadObject(); }\ncatch (EndOfStreamException)\n{\n    // declared length exceeded available bytes: input truncated\n}","preventionTips":["Buffer non-seekable or network streams fully before parsing","Reset stream Position to 0 before handing a stream to the parser","Verify transfer completeness (sizes/hashes) for downloaded certs/keys"],"tags":["asn1","der","eof","truncated-data"],"backgroundTag":"asn1-truncated-stream","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}