Stack-based buffer overrun on Windows RT (ARM)


  • Hi,

    I'm develop an Windows Store APP on Windows RT (ARM) platform.

    I run into a problem that when I use debug build, there's no any exception of my app, even if I didn't attach to VS2012.

    But when I use release build, VS2012 shows the following exception:

    "Stack cookie instrumentation code detected a stack-based buffer overrun."

    And it just break at a point without any problem (that line is void function return).

    My question is:

    1. What can be the root cause of this exception?

       1-1 Does is mean there are some buffer(s) I didn't correctly initialize/allocate, but somehow my debug compile setting or debug library does it for me?

       1-2 Is there any rules or guidelines when developing Windows RT programs in C++? Like structure size or buffer size limit?

    Tuesday, March 19, 2013 9:10 AM


All replies

  • From the link that follows it would appear that you didn't correctly initialize/allocate a buffer.   I suspect debug doesn't use the /GS setting which is why you are not seeing it until release.   The following link will provide you an excellent overview:

    http://www.developer.com/security/article.php/3417861/Visual-C-Protecting-Against-Buffer-Overruns-with-the-GS-Switch.htm  an excerpt follows:

    The reason that stack-based buffer overruns are so easily exploitable is that the return address for a function is stored on the stack by instructions that the compiler generates. Recognizing that the compiler plays a small part in causing the problem, the Visual C++ team took the approach with the release of Visual C++.NET (7.0) that the compiler could play a part in alleviating the problem. They inserted a generated cookie with a known value in the stack below the data that held the return address of a function. By using this technique, a buffer overrun that changes the value of the function's return address will also overwrite the cookie, which can be detected when the function returns. When a modified cookie is detected, a security exception is raised, and if the exception is not handled, the process that is running the code will exit.

    The guidelines for development would be more a C++ thing then a Windows RT one; you are just running into a protection mechanism.

    MCAD.NET C# - http://www.Global-webnet.com/Blog

    Tuesday, March 19, 2013 10:02 AM
  • Hi Bill,

    I check all project I used and all of them have turned on /GS setting in debug configuration.

    I think root cause will be another reason.

    Still thanks for you information very much!

    • Edited by truckwu Wednesday, March 20, 2013 4:14 AM Description not clear
    Wednesday, March 20, 2013 4:07 AM
  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to SkyDrive

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    If you don't want to upload the sample code, you can try to get the paid support from https://getsupport.microsoft.com/

    Best regards,

    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 21, 2013 3:14 AM
  • Here is some additional information.  Possibly you could try and simplify the code and see if the problem still occurs.  You might find the overrun that way.


    Best Wishes - Eric

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, April 8, 2013 10:44 PM