mity / mctrl

C library providing set of additional user interface controls for Windows, intended to be complementary to standard Win32API controls from USER32.DLL and COMCTL32.DLL.
http://mctrl.org
235 stars 52 forks source link

Broken image in example ex_html.exe on Windows 8 and 8.1 #13

Open mity opened 11 years ago

mity commented 11 years ago

When running ex_html.exe built with mingw-w64 on Windows 8 and 8.1, a PNG image is not shown in the HTML page.

mity commented 11 years ago

screenshot

mity commented 11 years ago

Investigation showed the following facts:

mity commented 11 years ago

More observations:

mity commented 10 years ago

Even more observations. It seems that many conditions have to be met in order to reproduce the bug:

Gosh. This issue is big mystery to me.

As the issue seems to be related to layout of resources in .rsrc section, I performed several analyzes and experiments.

  1. Updated ex_html.exe to access the "broken" resources with FindResource() + LoadResource() on app. exit (i.e. after the bug happens) and saved them to a file. They are genuine and same as the "unbroken" originals.
  2. Commented the image resource in resource script. Other resource (the doc.html) got broken.
  3. Placed various padding resources (custom resources created from zero-filled blocks of given length, never loaded by the program). Seems that resource of type 23 (i.e. RT_MANIFEST - 1) which is long enough "fixes" the issue.
  4. Retried (3) and (2) together. Required length of the padding differs.
  5. Retried (2), (3) and (4) with 32 as well as 64-bit builds, and with various compile time options. For given resource script, the minimal length to "fix" the issue is always constant.
  6. Tried to edit resources in "broken" ex_html.exe with resource hacker: Added a dummy resource, saved and then removed it back. This way, I assume, I forced the Windows API (BeginUpdateResource() + related functions). Result was not same as that one of RC.EXE but much closer then windres.exe. Again this "fixed" the issue.

Is it possible there is incompatibility between windres, and some part of Windows 8 (which may be the embedded browser, dynamic loader which surely interprets the manifest or whatever)???

Manually analyzed hex-dump of the .rsrc section, both from ex_html.exe built with gcc and MSVC:

mity commented 10 years ago

Tried once again to verify correctness of mCtrl.dll + ex_html.exe code:

mity commented 10 years ago

Enabled HTML traces (-DHTML_DEBUG=1), run ex_html.exe multiple times. When compared the 1st run (when the bug happens) and subsequent runs (when it does not):

mity commented 10 years ago

What the hell is going on??

mity commented 10 years ago

Tried one more intersting experiment:

  1. Compiled ex_html.rc into ex_html.rc.obj by windres from the mingw-w64 toolchain.
  2. Compiled ex_html.c into ex_html.c.obj by MSVC 12 compiler.
  3. Linked the two together with MSVC 12 linker.

The bug is still there. By this I consider more or less proved the issue is about incompatibility of windres from GNU binutils and something in Windows 8 or 8.1. Given the bug happens only on the 1st run, it may involve some caching in some Windows subsystem.

Perhaps dynamic loader somehow and very subtly breaks state of loaded ex_html.exe image when accessing the application manifest in it (in a way colliding only with resource layout as output by windres but not RC.EXE. Arguably, Windows might cache the manifest for next app. starts so the subsequent starts do not trigger the bug. But this paragraph is pure speculation.

mity commented 10 years ago

Reported in binutils bugzilla: https://sourceware.org/bugzilla/show_bug.cgi?id=17184