{"id":661,"date":"2017-08-14T18:05:27","date_gmt":"2017-08-14T16:05:27","guid":{"rendered":"https:\/\/www.neunbeere.de\/blog\/?p=661"},"modified":"2017-12-14T16:33:20","modified_gmt":"2017-12-14T15:33:20","slug":"graphics-bug-in-windows-7-after-installing-august-2017-security-updates","status":"publish","type":"post","link":"https:\/\/www.neunbeere.de\/blog\/2017\/08\/graphics-bug-in-windows-7-after-installing-august-2017-security-updates\/","title":{"rendered":"Graphics Bug in Windows 7 after installing August 2017 Security Updates"},"content":{"rendered":"<p><em>Update: Microsoft has <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/4039884\/windows-7-update-kb4039884\">provided a fix<\/a>.<\/em><\/p>\n<p>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: <\/p>\n<ul>\n<li>Symptoms of the problem<\/li>\n<li>What triggers the problems<\/li>\n<li>Workarounds<\/li>\n<li>Technical background<\/li>\n<\/ul>\n<h2>Symptoms of the problem<\/h2>\n<p>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.<\/p>\n<p>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.<\/p>\n<h2>What triggers the problems<\/h2>\n<p>The problem appears when all of the following conditions are met:<\/p>\n<ol>\n<li>Windows 7 (or Windows Server 2008)<\/li>\n<li>The patches of KB4034664 or KB4034679 are fully installed<\/li>\n<li>The currently logged on user is not a local System Administrator on the computer, but a user with limited rights or a domain user<\/li>\n<li>The system has multiple monitors<\/li>\n<li>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<\/li>\n<li>An application window is positioned so that it is within the area of the screen that has negative screen coordinates.<\/li>\n<li>This application window uses the Windows API function &#8220;StretchDIBits&#8221; (or a variant) to draw a graphic on a device context directly linked to that window.<\/li>\n<\/ol>\n<h2>Workarounds<\/h2>\n<p>These workarounds exist:<\/p>\n<ol>\n<li>Upgrade to Windows 10 \/ Server 2012<\/li>\n<li>Uninstall KB4034664 \/ KB4034679 patches from the system<\/li>\n<li>Log on with a user that is a full local administrator<\/li>\n<li>Only use the application on the main monitor, not a secondary monitor<\/li>\n<li>Arrange the monitors such that no part of a monitor has negative screen coordinates. (See details in next paragraph)<\/li>\n<\/ol>\n<p>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.<\/p>\n<p>Consider the following setups. An area circled in red marks an area with negative screen coordinates where these graphics problems will occur.<\/p>\n<p><div id=\"attachment_666\" style=\"width: 1010px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-666\" src=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorLeft.png\" alt=\"\" width=\"1000\" height=\"568\" class=\"size-full wp-image-666\" srcset=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorLeft.png 1000w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorLeft-300x170.png 300w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorLeft-768x436.png 768w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorLeft-500x284.png 500w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><p id=\"caption-attachment-666\" class=\"wp-caption-text\">A secondary monitor arranged left of the main monitor causes the graphics problems.<\/p><\/div><div id=\"attachment_668\" style=\"width: 1025px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-668\" src=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorUp.png\" alt=\"\" width=\"1015\" height=\"528\" class=\"size-full wp-image-668\" srcset=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorUp.png 1015w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorUp-300x156.png 300w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorUp-768x400.png 768w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorUp-500x260.png 500w\" sizes=\"auto, (max-width: 1015px) 100vw, 1015px\" \/><p id=\"caption-attachment-668\" class=\"wp-caption-text\">A secondary monitor arranged higher than the main monitor causes the graphics problems.<\/p><\/div><br \/>\n<div id=\"attachment_670\" style=\"width: 1044px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-670\" src=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay.png\" alt=\"\" width=\"1034\" height=\"591\" class=\"size-full wp-image-670\" srcset=\"https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay.png 1034w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay-300x171.png 300w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay-768x439.png 768w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay-1024x585.png 1024w, https:\/\/www.neunbeere.de\/blog\/wp-content\/uploads\/2017\/08\/XMonitorOkay-500x286.png 500w\" sizes=\"auto, (max-width: 1034px) 100vw, 1034px\" \/><p id=\"caption-attachment-670\" class=\"wp-caption-text\">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<\/p><\/div><\/p>\n<h2>Technical background<\/h2>\n<p>The actual problem seems to be within the Windows API Function &#8220;StretchDIBits&#8221;. 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.<\/p>\n<p>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. <\/p>\n<p>Here is the relevant source code:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nprocedure TForm1.PaintBox1Paint(Sender: TObject);\r\nvar\r\n  lResult: Integer;\r\n  Bitmap: TBitmap;\r\n  BitmapHeader:  pBitmapInfo;\r\n  BitmapImage :  POINTER;\r\n  HeaderSize  :  DWORD;\r\n  ImageSize   :  DWORD;\r\nbegin\r\n  Bitmap:= TBitmap.Create;\r\n  try\r\n    Bitmap.LoadFromResourceName(HInstance, 'Bitmap_1');\r\n\r\n    GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);\r\n    GetMem(BitmapHeader, HeaderSize);\r\n    GetMem(BitmapImage,  ImageSize);\r\n    try\r\n       GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);\r\n       lResult :=   StretchDIBits(Canvas.Handle,\r\n                      0, 0,     \/\/ Destination Origin\r\n                      300, \/\/ Destination Width\r\n                      300,  \/\/ Destination Height\r\n                      0, 0,                            \/\/ Source Origin\r\n                      300,     \/\/ Source Width &amp; Height\r\n                      300,\r\n                      BitmapImage,\r\n                      TBitmapInfo(BitmapHeader^),\r\n                      DIB_RGB_COLORS,\r\n                      SRCCOPY)  ;\r\n\r\n       Canvas.MoveTo(0,0);\r\n       Canvas.LineTo(PaintBox1.Width, PaintBox1.Height);\r\n\r\n       Label1.Caption := 'Result ' + IntToStr(lResult);\r\n       if(lResult = 0) then\r\n       begin\r\n         Label1.Font.Color := clRed;\r\n       end\r\n       else\r\n       begin\r\n         Label1.Font.Color := clBlack;\r\n       end;\r\n    finally\r\n      FreeMem(BitmapHeader);\r\n      FreeMem(BitmapImage)\r\n    end;\r\n  finally\r\n    FreeAndNil(Bitmap);\r\n  end;\r\nend;\r\n\r\n<\/pre>\n<p>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 &#8220;300&#8221;. 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 &#8220;0&#8221;.<\/p>\n<h2>Fixed by Microsoft<\/h2>\n<p>A fix for the bug was rolled out in September 2017 with the monthly rollout of Windows Updates under the numbers <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/4038779\/windows-7-update-kb4038779\">KB4038779<\/a> and <a href=\"https:\/\/support.microsoft.com\/en-us\/help\/4038777\">KB4038777<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: &hellip; <a href=\"https:\/\/www.neunbeere.de\/blog\/2017\/08\/graphics-bug-in-windows-7-after-installing-august-2017-security-updates\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[43,202,194,203],"class_list":["post-661","post","type-post","status-publish","format-standard","hentry","category-programmierung","tag-bug","tag-graphics","tag-microsoft","tag-windows-7"],"_links":{"self":[{"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/posts\/661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":13,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":680,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions\/680"}],"wp:attachment":[{"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.neunbeere.de\/blog\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}