none
"How to debug Buffer Overrun Issues"

    Question

  • My program crashed with the error message:

    A buffer overrun has occurred in TestLogger.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

    For more details please see Help topic 'How to debug Buffer Overrun Issues'.

    Yet when I search for "How to debug Buffer Overrun Issues" I don't find anything close to that. The closest I get is an article from "Writing Secure Code" about prevention of buffer overrun, but my program is already preventing buffer overrun as much as I know. I need to find the article that the error message says to find.

    Monday, June 18, 2007 12:30 AM

All replies

  • Hmm, you must have had a pretty big overrun on the stack to cause that. Most likely you have a string which wasn't null terminated and you then used strlen to count the length.

    Have you used strncpy in your program? If you have then you have to remember that it doesn't add the null character if the length of the string is longer than the value you pass to it.

     

    I can't say much for other people but this is the general things I do to find out where a buffer overrun is occuring.

     

    1) Keep an additional variable for each string containing the length of the string.

    2) Step through each function which contains string operations and check the sizes of each string and make sure there is enough room.

     

    Other things which I do to help prevent things like this.

     

    1) Never allocate a string on the stack. All strings I create are on the heap.

    2) All strings are created with a maximum possible length. If there is any string inputted then it is truncated to the maximum length.

    3) I don't reuse buffers if I don't need to. If I want to put a string into memory, it is either a readonly constant or I allocate the buffer just as I copy the string, freeing any previously allocated memory first.

    4) I have a custom strlen function which takes the maximum possible size of the string as a parameter. This means, if the target buffer is 51 chars then I will pass 50 as a parameter to the strlen function. If it is more than 50 chars then it will return 50 otherwise it will return the length of the string.

    5) I always explicitly have one character reserved for the null character. If I allocate enough room for a 40 character string, I will make sure that I allocate 41 characters worth of memory.

    6) I always initialise the entire buffer to 0 before I use it.

    Monday, June 18, 2007 2:06 AM
  • You'll get a lot more information on BOs if you use windbg. When the BO traps, use "!analyze -v" and it will give you a lot of diagnostic info, including the cookie that was overwritten and what the debugger thinks might be the buffer that was overrun.
    Monday, June 18, 2007 2:46 AM
  • Thank you; both you and Sdi.

     

    Note that I am posting this question to determine where the article is that the error message is referring to. I did not intend to ask how to debug buffer overruns, but I appreciate the help. Since this forum is part of the VC 2005 documentation, I think it would help others to be able to find the article the message refers to. Either the relevant software needs to be patched to change the message, or the topic that the message refers to should be returned from whereever it went.

     

    In answer to the question whether I use strncpy, I am nearly certain I do not use it in this program, but I will check. I know I use the secure functions such as strcpy_s whenever available. I also use localtime_s and strftime; I have not looked at those functions extensively but there are multiple reasons why I am confident they are not the problem. Whatever the problem is, the buffer overrun is likely a symptom of something else. My code is probably not causing the buffer overrun directly. The problem is likely something relatively obscure, such as using a function name without parentheses (function instead of function()). I don't know if that specific example could be the cause, but it is an exmple only.

    Monday, June 18, 2007 4:48 AM
  • I have a VB 6 project that uses an ActvieX wrapping my .NET dlls. When I run the VB6 executable and attach the .NET debugger everything works fine but without the debugger attached I get a Buffer Overrun Excetion which crashes the app.

    The fact that it's running fine under debugger means that there is not C++ memory problems. Any idea how can I debug this issue?

     

    Thanks,

    Armand

     

    Thursday, October 04, 2007 6:17 PM
  • I have a completelty different Buffer overrun problem

     

    Use XPpro/SP2 fully updated

     

    Installed Quicktime Player 7.2 from Apple and in  "help" I clicked  "Update Existing Software"

     

    Immediatelty got panel  Microsoft Visual C++ runtime Library

                                                      Buffer overun detected

                                                       Cannot continue, etc

     

    I need guidance to cure this please.

     

    Daniel

    Sunday, October 07, 2007 9:55 PM
  •  Danielarbib wrote:

    I have a completelty different Buffer overrun problem

     

    Use XPpro/SP2 fully updated

     

    Installed Quicktime Player 7.2 from Apple and in  "help" I clicked  "Update Existing Software"

     

    Immediatelty got panel  Microsoft Visual C++ runtime Library

                                                      Buffer overun detected

                                                       Cannot continue, etc

     

    I need guidance to cure this please.

     

    Daniel

    I am sorry, but this forum is for developers to request assistance with (or for) software they are developing. You are more likely to get help in a TechNet forum, but for this problem you will likely be told to request support from Apple. Apple is the developer of Quicktime and only they can fix the problem.

    Sunday, October 07, 2007 10:08 PM
  • Dear All,


    I also got  the same  Buffer Overrun error Sam got. "A buffer overrun has occurred in ImageCLR.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.For more details please see Help topic 'How to debug Buffer Overrun Issues."

    But the PROBLEM here is, after getting that error on the current project (ImageCLR), all previous working projects also cannot be executed. They also gave the Buffer Overrun error.

    Wonder wether one BO error has affected all other working projects! I don't have any clue.

    About the Project(s):

    I'm using VS 2005 C++.NET with VTK for Image Processing. When try to debug the C++ code it stops at the line,

    vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();
    cylinderMapper->SetInput(cylinder->GetOutput());

    vtkPolyDataMapper is a class in VTK. I'm using CLR Windows Form to render and draw some images with VTK on a Panel.

    Your point of views will guide my thinking into unseen dimensions.

    Thanks in advance!

    BR,

    Chatura




    Tuesday, November 13, 2007 7:24 AM
  • Please understand, Chatura, that my question is not asking how to diagnose the problem; my question is about the topic "How to debug Buffer Overrun Issues" that the message says to go to but the topic does not exist.

     

    It will be better if you create a new thread with your question. Include everything in that thread that you have provided about your problem. Your problem is very, very different from the problem I had. I think it is nearly certain that there is a peice of code that is common among all the affected projects, so it will help if you describe what you have done recently that is common among all affected projects. Do that in the new thread, not here. It will help very much if you post a link here to the new thread, so anyone that sees this can find the new thread easily, especially if they want to help you.

     

    Buffer overrun errors are actually very common. It essentially means that somehow memory is being written to that should not be. If you create a new thread then someone, perhaps I, will explain further.

    Tuesday, November 13, 2007 8:56 AM
  • Thanks Sam for feedback. Anyway I have already put this into a new thread.

    BTW, a common issue was there; the relevant topic does not exist in the VS 2005 help. Also unable to browse for a sufficient answer.

    Since this is added to a new thread too hope someone can explain it.

    Thanks.
    Tuesday, November 13, 2007 9:38 AM
  • Hi Sam,

     

    I have run into same problem with VS 2005. Call stack is sometimes useless from with in VS. Try using WinDbg or CDB. I found the right function where the buffer overrun exception is being thrown by using WinDbg.

     

    Best Regards.

     

    Tuesday, February 26, 2008 10:07 PM
  •  

    it's funny how nobody's paying attention to the question that Sam's asking! Sam, i have the same problem, i've been referred to a Microsoft help topic called, "How to debug Buffer Overrun Issues," yet i cannot find this article. it sounds really good! Microsoft might want to  make it available to people, especially when they tempt us by talking about  it! wish i could find it and help you.

     

    best 

    Monday, April 14, 2008 10:34 PM
  • Thank you for the support. I wish I could help you more.

     

    You should create a new thread (you probably intend to) and describe your problem. A buffer overrun is a symptom; it is unlikely it is the actual problem. Your problem is likely very different from mine so you need to explain your program as much as possible. It is however difficult to know how to say and how much source code to show with out saying and/or showing too much.

     

    The way I diagnosed the problem is that I created a smaller version of my program. My program is a DLL that had become quite large. I made a console program that used just the relevant portion of my code that recreated the problem. Then I deleted portions of the program until the problem went away. I eventually had a small peice of code that recreated the problem. Then when I posted that small peice of code, people here noticed I was doing something stupid that I was overlooking.

     

    Ideally, that is not the best way to diagnose the problem, but there often is not an easy way to diagnose problems such as this. I sure am interested in knowing if Microsoft has something that helps that they have not told us about. Unfortunately, it is often difficult to diagnose this problem (the symptom). I hope you are lucky.

     

    Tuesday, April 15, 2008 1:46 AM
  • I don't know if this is the article they are referring to, but there isn't much there.

     

    http://msdn2.microsoft.com/en-us/library/ms717795(VS.85).aspx

     

    This error is being reported by the stack checking feature (lookup option /GS).  In this case, if you run your app under the VS2005 debugger, the output window will show you exactly what var is being overwritten

     

    Run-Time Check Failure #2 - Stack around the variable 'pTestBuf' was corrupted.

    A buffer overrun has occurred in TestCrash.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

     

     

    Tuesday, April 15, 2008 4:03 AM
  •  

    There's some additional info here:


    Compiler Security Checks In Depth
    http://msdn2.microsoft.com/en-us/library/aa290051.aspx

     

    Security Checks at Runtime and Compile Time
    http://msdn2.microsoft.com/en-us/library/aa289171.aspx

     

     

    - Wayne

     

    Tuesday, April 15, 2008 4:45 AM
  • Late reply, but I found this on google and thought I would post a response.

    There is a small trap for those migrating from VC6 to VC8 or greater with method pointers that can cause this error.

    If you have a method pointer defined typedef void CApp::*MethodPointer(char*) for example and your method is CApp::Method(void).

    If you then call CApp::Method using the method pointer type you will get the error described. This is becuase the method you are calling has different parameters, so you need to change CApp::Method(void) to CApp::Method(char*) or cast the params. You wont pick this up in debug builds either, only release.


     This has caught me out a few times now when migrating code. Its pretty straight foward when you find it, but it can leave you scratching your head for a while.
    Friday, October 03, 2008 1:13 AM
  • Hi,

    I had the same error message in a program I wrote, made of several DLLs and EXEs.
    I found out that the cause of the problem was that I accidentally compiled each DLL/EXE with a different Runtime Library (/MTd, /MD etc.)
    It turns out that you must use the same runtime library for all DLLs and EXEs in your project.
    To check it, go (in Visual Studio C++ 2005 etc.) to the projects' properties under C/C++ --> Code generation --> Runtime library  and make sure all projects use the same setting there.
    Hope it helps anyone.

    Omri

    • Edited by omrio Monday, October 06, 2008 7:12 PM
    • Proposed as answer by omrio Monday, October 06, 2008 7:13 PM
    Monday, October 06, 2008 7:10 PM
  • Well, its good to know that Microsoft STILL has not fixed this nonsense in their IDE.

    Using Visual Studio 2008 (VS 9) [stupid dual naming drives me nuts, but thats another rant]

     

    VS C++ debugger is STILL spitting out a message refering developers to this article.

     

    And searching for that article in the VS help system still returns ZERO matches. 

     

    So will someone at Microsoft get off of their butt and fix this already!

    Tuesday, August 11, 2009 11:29 PM
  • Yes, I ran into the same issue.
    Microsoft reports: "For more details please see Help topic 'How to debug Buffer Overrun Issues'." Yet no such topic exists, just thought I'd mention it here again to show my frustration.
    I figured if enough people hit this maybe it'd get appropriately answered.
    Friday, December 04, 2009 12:43 AM
  • And it's still an issue with Visual Studio 2010. Same error message with a reference to the help topic, but nothing in help or anything close to it!
    Frank
    Wednesday, November 03, 2010 11:15 PM
  • Four years later, and they are still referring to an article that doesn't exist, you search the Help and you get this thread only!  At least there are some helpful suggestions in here! 
    Thursday, July 07, 2011 2:49 PM
  • Four years later, and they are still referring to an article that doesn't exist, you search the Help and you get this thread only!  At least there are some helpful suggestions in here! 

    Make that FIVE years later...I just got referred to "please see Help topic 'How to debug Buffer Overrun Issues'".

    Monday, May 14, 2012 4:58 PM
  • yup, five years and counting.. I just got here because of the same useless reference to "please see Help topic 'How to debug Buffer Overrun Issues'".
    Wednesday, June 27, 2012 7:10 AM
  • yup, five years and counting.. I just got here because of the same useless reference to "please see Help topic 'How to debug Buffer Overrun Issues'".

    Welcome to the club :( Visual C++ 2012 with MFC
    Monday, December 24, 2012 1:18 AM
  • Make it 7 years! I'm using VS 2012 (in the year of our lord 2014) and received the same Buffer Overrun message - and received the same message: Please see Help topic 'How to debug Buffer Overrun Issues'.

    A topic that still does not exist after 7 years!

    Tuesday, September 23, 2014 4:48 PM