{"record":{"id":"ac78a7a42cc35563","repo":"peass-ng/PEASS-ng","slug":"data-overflow","errorCode":null,"errorMessage":"Data Overflow","messagePattern":"Data Overflow","errorType":"exception","errorClass":"StreamOverflowException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/io/Streams.cs","lineNumber":86,"sourceCode":"\t\t/// A <see cref=\"Stream\"/>\n\t\t/// </param>\n\t\t/// <param name=\"limit\">\n\t\t/// A <see cref=\"System.Int64\"/>\n\t\t/// </param>\n\t\t/// <param name=\"outStr\">\n\t\t/// A <see cref=\"Stream\"/>\n\t\t/// </param>\n\t\t/// <returns>The number of bytes actually transferred, if not greater than <c>limit</c></returns>\n\t\t/// <exception cref=\"IOException\"></exception>\n\t\tpublic static long PipeAllLimited(Stream inStr, long limit, Stream outStr)\n\t\t{\n\t\t\tbyte[] bs = new byte[BufferSize];\n\t\t\tlong total = 0;\n\t\t\tint numRead;\n\t\t\twhile ((numRead = inStr.Read(bs, 0, bs.Length)) > 0)\n\t\t\t{\n\t\t\t\tif ((limit - total) < numRead)\n\t\t\t\t\tthrow new StreamOverflowException(\"Data Overflow\");\n\t\t\t\ttotal += numRead;\n\t\t\t\toutStr.Write(bs, 0, numRead);\n\t\t\t}\n\t\t\treturn total;\n\t\t}\n\n\t\t/// <exception cref=\"IOException\"></exception>\n\t\tpublic static void WriteBufTo(MemoryStream buf, Stream output)\n\t\t{\n\t\t\tbuf.WriteTo(output);\n\t\t}\n\n\t\t/// <exception cref=\"IOException\"></exception>\n\t\tpublic static int WriteBufTo(MemoryStream buf, byte[] output, int offset)\n\t\t{\n#if PORTABLE\n            byte[] bytes = buf.ToArray();\n            bytes.CopyTo(output, offset);","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/io/Streams.cs#L68-L104","documentation":"Streams.PipeAllLimited copies at most `limit` bytes from inStr to outStr. If reading more bytes would exceed the limit, it throws StreamOverflowException('Data Overflow'). This protects against unbounded input (decompression bombs, huge payloads) exhausting memory or disk.","triggerScenarios":"Calling PipeAllLimited (directly or via ReadAllLimited) on a stream whose total readable bytes exceed the configured limit — e.g. limit=1024 but the stream delivers 2000 bytes.","commonSituations":"Reading decompressed data larger than an expected maximum; parsing attacker-controlled embedded blobs; processing files bigger than an application-enforced cap.","solutions":["Raise the limit parameter to a value above the legitimate maximum expected size.","Pre-check the source length (stream.Length if seekable) against the limit before piping.","Treat the exception as a guard: reject the input as oversized rather than increasing limits blindly for untrusted data.","Read in bounded chunks yourself and enforce your own policy (truncate, reject, or stream to disk)."],"exampleFix":"// before\nStreams.PipeAllLimited(input, 1024, output); // input has 4096 bytes\n// after\nlong max = input.CanSeek ? input.Length : long.MaxValue;\nif (max > 1024) throw new InvalidOperationException(\"payload too large\");\nStreams.PipeAllLimited(input, 1024, output);","handlingStrategy":"try-catch","validationCode":"if (input.CanSeek && input.Length > limit) throw new InvalidOperationException(\"stream exceeds limit\");","typeGuard":"static bool WithinLimit(Stream s, long limit) => !s.CanSeek || s.Length <= limit;","tryCatchPattern":"try { Streams.PipeAllLimited(inStr, limit, outStr); } catch (StreamOverflowException) { throw new PayloadTooLargeException(limit); }","preventionTips":["Set limits above the legitimate maximum with headroom","Pre-check stream length when seekable","Treat overflow of untrusted input as rejection, not a limit to raise"],"tags":["csharp","io","stream","limits"],"backgroundTag":"stream-overflow","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}