peverify "stack height" and enforcement by the .NET run time? RRS feed

  • Question

  • The following error is displayed by peverify, but the .NET run time allows assemblies containing this error to execute:

    "Stack height at all points must be determinable in a single forward scan of IL."

    According the CLI standard, this occurs because the "Backwards Branch Constraint" is violated in the IL. The constraint is defined as follows:

    'It must be possible in a single forward-pass through the CIL instruction stream for any method to infer the exact state of the evaluation stack at every instruction (where by "state" we mean the number and type of each item on the evaluation stack.'

    The rationale in the Annotated Standard states this:

    "This constraint ensures that CIL code can be processed by a simple CIL-to-native-code compiler. It ensures that the state of the evaluation stack at the beginning of each CIL can be inferred from a single, forward-pass analysis of the instruction stream."

    Can anyone shed any light on why the .NET run time does allows assemblies violating this rule to execute?

    Are there any known plans to change the .NET run time so that it enforces this rule?
    Wednesday, January 7, 2009 10:41 PM


  • This is a security check.  I think it depends on how you are running your code.  You are probably running your code with full trust, so the runtime bypasses this kind of security check to improve performance.

    Couldn't find the official documentation page that says this, but discusses an example where verification happens only under partial trust.

    > Are there any known plans to change the .NET run time so that it enforces this rule?

    There is no need to change it.  Fully trusted code is allowed to do unsafe things.

    • Marked as answer by Zhi-Xin Ye Tuesday, January 13, 2009 11:13 AM
    Wednesday, January 7, 2009 11:34 PM