ReadConsoleOutput cause "Access violation writing location" exception RRS feed

  • Question

  • Bug in KernelBase appears from Windows 8 and still alive in Windows 8.1 console!
    In breaf - "First-chance exception at ... (ntdll.dll) in ...: 0xC0000005: Access violation writing location" is occured (always) when application calls ReadConsoleOutput function and ReadRegion lies out of scrollable area (buffer).

    Previous versions of Windows survives, function just returns an error without crashing the application.

    Sample code:

    GetConsoleScreenBufferInfo(h, &csbi); 
    COORD crNoScroll = {min(80,csbi.srWindow.Right-csbi.srWindow.Left+1), min(25,csbi.srWindow.Bottom-csbi.srWindow.Top+1)}; 
    SetConsoleScreenBufferSize(h, crNoScroll); 
    CHAR_INFO* pLine = new CHAR_INFO[csbi.dwSize.X]; 
    COORD bufSize = {csbi.dwSize.X,1}; COORD bufCoord = {0,0}; SMALL_RECT rgn = {0,9998,csbi.dwSize.X-1,9998}; 
    // Here will be a crash! Example: 
    // First-chance exception at 0x7789F073 (ntdll.dll) in BufferTrap.exe: 0xC0000005: Access violation writing location 0x00A3E000. 
    ReadConsoleOutputW(h, pLine, bufSize, bufCoord, &rgn);

    Don't suggest to pass correct reading region!

    Windows is multitasking OS, yeah? So, any application in the same console may change buffer height at any moment. Application can't ensure, that between GetConsoleScreenBufferInfo and ReadConsoleOutput there was no changes in buffer height!
    Kernel must not crash application.

    Tuesday, August 13, 2013 10:44 PM

All replies

  • Hi ConEmu.Maximus5 ,

    Welcome to MSDN forum!

    Would you mind to send me your project?

    If this is a bug, i'd like to send it as bug. But before that, i should reproduce it.

    If you feel awkward about it, please guide me step by step to reproduce it.

    Best Regards!

    Monday, August 19, 2013 6:31 AM
  • Hi, Xiaoliang Chen

    Sample poject is located here:

    and cpp file alone - here:

    Just compile and run exe in Windows 8 or Windows 8.1 - crashed in 100%. Some users report same problem in Windows 7, but I can't confirm that.

    Thanx in advance

    Monday, August 19, 2013 7:59 AM
  • Hi ConEmu.Maximus5 ,

    I have got it, and i'm going to test your sample, i'll give you a info as soon as i draw a conclusion.

    Best Regards!

    Monday, August 19, 2013 8:24 AM
  • Also, just now there was bugreport (on my application) about that crash in Windows 7 x64 SP1.

    User have uploaded crash dump that confirm ReadConsoleOutput problem in that OS too.

    Monday, August 19, 2013 6:41 PM
  • Hi ConEmu.Maximus5 ,

    I have  tested your code , and found the error on Win8.

    I have sent this sample code to a professional  engineer for testing it on Win8.1.

    So please wait patiently.

    Best Regards!

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, August 20, 2013 1:06 AM