I have a top-level console app targeting net5 with this code:
Work();
void Work()
{
Work();
}
It will eventually throw a StackOverflowException
and print to the console the last known stack size. Here are the results of a few runs:
32120
32113
32133
32127
I also see this variability of the stack size when I target .net framework 4.8.
I looked at ECMA-335 Standard: Common Language Infrastructure and found this sentence, regarding StackOverflowException
: "The precise timing of this exception and the conditions under which it occurs are implementation-specific".
Then I found out about ASLR (address space layout randomization), and thought that perhaps the CLI implementation uses a similar technique.
My question is, why does this variability exist and if ASLR is turned off, how could a potential attack work?