{"record":{"id":"1ac4b4114d3f7d9e","repo":"peass-ng/PEASS-ng","slug":"eof-encountered-in-middle-of-bmpstring","errorCode":null,"errorMessage":"EOF encountered in middle of BMPString","messagePattern":"EOF encountered in middle of BMPString","errorType":"exception","errorClass":"EndOfStreamException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs","lineNumber":343,"sourceCode":"            defIn.ReadAllIntoByteArray(buf);\n\n            return buf;\n        }\n\n        private static char[] GetBmpCharBuffer(DefiniteLengthInputStream defIn)\n        {\n            int remainingBytes = defIn.Remaining;\n            if (0 != (remainingBytes & 1))\n                throw new IOException(\"malformed BMPString encoding encountered\");\n\n            char[] str = new char[remainingBytes / 2];\n            int stringPos = 0;\n\n            byte[] buf = new byte[8];\n            while (remainingBytes >= 8)\n            {\n                if (Streams.ReadFully(defIn, buf, 0, 8) != 8)\n                    throw new EndOfStreamException(\"EOF encountered in middle of BMPString\");\n\n                str[stringPos] = (char)((buf[0] << 8) | (buf[1] & 0xFF));\n                str[stringPos + 1] = (char)((buf[2] << 8) | (buf[3] & 0xFF));\n                str[stringPos + 2] = (char)((buf[4] << 8) | (buf[5] & 0xFF));\n                str[stringPos + 3] = (char)((buf[6] << 8) | (buf[7] & 0xFF));\n                stringPos += 4;\n                remainingBytes -= 8;\n            }\n            if (remainingBytes > 0)\n            {\n                if (Streams.ReadFully(defIn, buf, 0, remainingBytes) != remainingBytes)\n                    throw new EndOfStreamException(\"EOF encountered in middle of BMPString\");\n\n                int bufPos = 0;\n                do\n                {\n                    int b1 = buf[bufPos++] << 8;\n                    int b2 = buf[bufPos++] & 0xFF;","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1InputStream.cs#L325-L361","documentation":"Thrown by GetBmpCharBuffer while converting a definite-length BMPString's contents into a char buffer: the underlying stream ended before all of the BMP string's bytes could be read, so the encoding claims more content bytes than the stream actually contains.","triggerScenarios":"A primitive BMPString whose definite-length content exceeds the actual bytes remaining in the stream (truncated input, or the DefiniteLengthInputStream hit EOF mid-string).","commonSituations":"Certificate files cut off mid-transfer; streams read after an earlier consumer already drained them; truncated embedded blobs in logs/databases.","solutions":["Verify the input length matches the ASN.1 structure (complete file/blob)","Buffer the whole source into a byte[] before parsing so the parser sees a self-consistent stream","Re-download/re-copy the data; check transfer integrity","Catch EndOfStreamException and treat the certificate/blob as truncated"],"exampleFix":"// before\nAsn1Object o = new Asn1InputStream(partialStream).ReadObject();\n// after\nif (partialStream.CanSeek && partialStream.Position != 0) partialStream.Position = 0;\nbyte[] all = ReadAllBytes(partialStream);\nAsn1Object o = Asn1Object.FromByteArray(all);","handlingStrategy":"try-catch","validationCode":"static bool IsCompleteFile(string path)\n{\n    var fi = new FileInfo(path);\n    return fi.Exists && fi.Length > 0; // plus upstream integrity checks (hash/size)\n}","typeGuard":null,"tryCatchPattern":"try { Asn1Object o = Asn1Object.FromByteArray(data); }\ncatch (EndOfStreamException)\n{\n    // BMPString (or object) content truncated mid-read\n}","preventionTips":["Fully materialize input as byte[] before parsing","Avoid sharing one Stream between multiple parsers","Validate downloads against expected size/hash"],"tags":["asn1","bmpstring","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"}