I’m running some unsecure code which I have set its stdout and stderr streams to FileStreams wrapped in PrintStreams. (Standard output/error MUST be redirected.)
Is there any way to configure those redirected FileStreams/PrintStreams to set a maximum of say 10 MB written, so that, for example,
while (true) System.out.write("lots of bytes");
doesn’t write excessive amounts of data to the server’s disk.
The code does have a time limit of 15s, but I’d like a separate guard here.
One way to do it is to define a
FilterOutputStreamthat you wrap the file stream in, which keeps an internal counter that it increments on everywrite, and after reaching a set threshold, starts throwingExceptionsor simply ignores the writes.Something along the lines of: