Graphics Bug in Windows 7 after installing August 2017 Security Updates

Update: Microsoft has provided a fix.

One of the security fixes included in the august 2017 updates for Windows contains a bug that causes graphics problems on multi monitor systems in some applications. This blog post contains the following information:

  • Symptoms of the problem
  • What triggers the problems
  • Workarounds
  • Technical background

Symptoms of the problem

In applications, graphics or controls are not shown or shown distorted. You might for example only see an empty background with missing foreground graphics or missing controls. Or you see the Desktop or parts of a different application in parts of the currently active application.

These graphical problems only appear on secondary monitors, not on the main monitor and possibly also depending on the position of the application window within the secondary monitor.

What triggers the problems

The problem appears when all of the following conditions are met:

  1. Windows 7 (or Windows Server 2008)
  2. The patches of KB4034664 or KB4034679 are fully installed
  3. The currently logged on user is not a local System Administrator on the computer, but a user with limited rights or a domain user
  4. The system has multiple monitors
  5. The monitors are setup such that certain parts of the screen have negative screen positions. For example a secondary monitor is setup to be left of the main monitor. Or a monitor is setup to have a higher top border than the main monitor
  6. An application window is positioned so that it is within the area of the screen that has negative screen coordinates.
  7. This application window uses the Windows API function “StretchDIBits” (or a variant) to draw a graphic on a device context directly linked to that window.

Workarounds

These workarounds exist:

  1. Upgrade to Windows 10 / Server 2012
  2. Uninstall KB4034664 / KB4034679 patches from the system
  3. Log on with a user that is a full local administrator
  4. Only use the application on the main monitor, not a secondary monitor
  5. Arrange the monitors such that no part of a monitor has negative screen coordinates. (See details in next paragraph)

In Windows, when you have multiple monitors, one of these monitors becomes the main monitor. Screen coordinates are relative to the main monitor. So, screen coordinates can be negative when a monitor is positioned left of or higher than the main monitor. You can use the Windows control panel to change which monitor is the main monitor and to position the secondary monitors relative to the main monitor.

Consider the following setups. An area circled in red marks an area with negative screen coordinates where these graphics problems will occur.

A secondary monitor arranged left of the main monitor causes the graphics problems.

A secondary monitor arranged higher than the main monitor causes the graphics problems.


Having all Secondary Monitors to the right of the Main Monitor and not positioned higher than the Main Monitor will work around these graphics problems

Technical background

The actual problem seems to be within the Windows API Function “StretchDIBits”. After the security update, when this function is used to draw graphics onto a part of the screen with negative screen coordinates, it fails and 1. does not actually draw the graphics on the screen and 2. actually returns the error code 0 to signal something went wrong. Microosft will have to fix this issue.

I could reproduce the issue in a very simple Delphi application. The application consists of a form with a TPaintBox. When the form is moved, it calls Invalidate on the form to ask Windows to repaint the form. In the OnPaint event of the paint box, a bitmap is painted on the paint box using StretchDIBits.

Here is the relevant source code:

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  lResult: Integer;
  Bitmap: TBitmap;
  BitmapHeader:  pBitmapInfo;
  BitmapImage :  POINTER;
  HeaderSize  :  DWORD;
  ImageSize   :  DWORD;
begin
  Bitmap:= TBitmap.Create;
  try
    Bitmap.LoadFromResourceName(HInstance, 'Bitmap_1');

    GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
    GetMem(BitmapHeader, HeaderSize);
    GetMem(BitmapImage,  ImageSize);
    try
       GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
       lResult :=   StretchDIBits(Canvas.Handle,
                      0, 0,     // Destination Origin
                      300, // Destination Width
                      300,  // Destination Height
                      0, 0,                            // Source Origin
                      300,     // Source Width & Height
                      300,
                      BitmapImage,
                      TBitmapInfo(BitmapHeader^),
                      DIB_RGB_COLORS,
                      SRCCOPY)  ;

       Canvas.MoveTo(0,0);
       Canvas.LineTo(PaintBox1.Width, PaintBox1.Height);

       Label1.Caption := 'Result ' + IntToStr(lResult);
       if(lResult = 0) then
       begin
         Label1.Font.Color := clRed;
       end
       else
       begin
         Label1.Font.Color := clBlack;
       end;
    finally
      FreeMem(BitmapHeader);
      FreeMem(BitmapImage)
    end;
  finally
    FreeAndNil(Bitmap);
  end;
end;

When running the application and moving the form, when the form is within an area of the screen with only positive screen coordinates, the bitmap is displayed and the label shows the expected value “300”. When the form is moved within an area with negative screen coordinates, the bitmap vanished and the label shows the function StretchDIBits returning the error code “0”.

Fixed by Microsoft

A fix for the bug was rolled out in September 2017 with the monthly rollout of Windows Updates under the numbers KB4038779 and KB4038777

18 thoughts on “Graphics Bug in Windows 7 after installing August 2017 Security Updates

  1. Pingback: This month’s Win7 patches KB 4034664, KB 4034679 causing second-screen problems @ AskWoody

  2. Thanks for the write up.

    We seem to be seeing the issue even on users who are full admin. An additional problem we are seeing is applications launching off screen. You can see them in the toolbar but can’t reposition, move , resize, or full screen them. You must deactivate all but the primary monitor to find it.

  3. Pingback: Windows Update KB4034664 is causing trouble on 2nd screen | Born's Tech and Windows World

  4. Pingback: Two of this month’s Win7 patches causing second-screen problems - The Gizmo Effect

  5. The caption on Workaround graphic #3 appears to be incorrect. The caption currently reads: “Having all Secondary Monitors Left of the Main Monitor and not positioned higher than the Main Monitor will work around these graphics problems” but the image shows, and the context would indicate, that it should say: “Having all Secondary Monitors positioned Right of the Main Monitor and not positioned higher than the Main Monitor will work around these graphics problems”

  6. Any chance Microsoft will fix this appropriately with a new KB update, or is the issue expected behavior as a result of the security fix?

  7. Looking at Microsoft statements in the KB4034664 website for known issues they are silent on a fix for this. They are aware of the issue. So I rearranged by Quad screens so my main screen is in the upper left. This solves the issue for me. I guess I will adapt to my new arrangements.

  8. I use Windows 7 Pro. Before reading this article – It took me two days to establish that it is windows security update kb4034664 that causes annoying and various secondary monitor rendering problems. After uninstalling the update all returned to normal. I’ m certainly not “upgrading” to windows 10 to cure the problem only to be presented with more …

  9. great articles even though the negative screen is not 100% correct.

    I confirmed removing both update 664 and 679 has resolved the issue.

  10. Great write-up. I laughed out loud that the first option for a workaround is to upgrade to Windows 10.

  11. Pingback: Microsoft patches buggy Windows 7 patch, KB 4039884 solves the dual-monitor rendering problem @ AskWoody

  12. Pingback: Microsoft repairs buggy Win7 security patch with buggy hotfix KB 4039884 – Netxtract

  13. Pingback: Microsoft repairs buggy Win7 security patch with buggy hotfix KB 4039884 – Nocturnal Zine

  14. It may have been a hiddend bug that always existed. i used to use starcom adapters in my work. and about half of them we could use nothing on the second screen. looking at this it might explain why or a similar issue. since updating the drivers never fixed it. admin would not make a difference for a graphics bug. will follow to see what else happens. and next time a starcom device comes in will try the monitor workaround to see if it goes away.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.