Skip to content

Commit

Permalink
Disable Bitmap round-tripping tests for old libgdiplus versions (#34354)
Browse files Browse the repository at this point in the history
* Fix filename typo

* Disable Bitmap round-tripping tests for old libgdiplus versions

Old libgdiplus versions have uninitialized stack variable bug that makes Bitmap round-tripping unreliable. The bug causes Bitmap.Flags, Bitmap.HorizontalResolution and Bitmap.VerticalResolution properties to be set to bogus values if the stack happens to contain certain bit patterns. This bug was fixed for libgdiplus 6 by mono/libgdiplus@81e45a1#diff-c96a8261ecb168c12b44248208da21c0R118.

* Fix and simplify gdiplus library loading
  • Loading branch information
jkotas committed Apr 1, 2020
1 parent 2ad6913 commit e1fa5d7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/libraries/Common/tests/System/Drawing/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public static bool GetIsWindowsOrAtLeastLibgdiplus6()
{
installedVersion = new Version(GetLibgdiplusVersion());
}
catch (DllNotFoundException)
{
return false;
}
catch (EntryPointNotFoundException)
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,20 @@ internal unsafe partial class Gdip

internal static IntPtr LoadNativeLibrary()
{
string libraryName;
var assembly = System.Reflection.Assembly.GetExecutingAssembly();

IntPtr lib = IntPtr.Zero;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
libraryName = "libgdiplus.dylib";

var assembly = System.Reflection.Assembly.GetExecutingAssembly();
NativeLibrary.TryLoad(libraryName, assembly, default, out lib);
NativeLibrary.TryLoad("libgdiplus.dylib", assembly, default, out lib);
}
else
{
// Various Unix package managers have chosen different names for the "libgdiplus" shared library.
// The mono project, where libgdiplus originated, allowed both of the names below to be used, via
// a global configuration setting. We prefer the "unversioned" shared object name, and fallback to
// the name suffixed with ".0".
libraryName = "libgdiplus.so";

var assembly = System.Reflection.Assembly.GetExecutingAssembly();
if (!NativeLibrary.TryLoad(libraryName, assembly, default, out lib))
if (!NativeLibrary.TryLoad("libgdiplus.so", assembly, default, out lib))
{
NativeLibrary.TryLoad("libgdiplus.so.0", assembly, default, out lib);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Compile Include="mono\System.Drawing.Imaging\GifCodecTests.cs" />
<Compile Include="mono\System.Drawing.Imaging\IconCodecTests.cs" />
<Compile Include="mono\System.Drawing.Imaging\JpegCodecTests.cs" />
<Compile Include="mono\System.Drawing.Imaging\PngCodecTesst.cs" />
<Compile Include="mono\System.Drawing.Imaging\PngCodecTests.cs" />
<Compile Include="mono\System.Drawing.Imaging\TiffCodecTests.cs" />
<Compile Include="mono\System.Drawing\GraphicsTests.cs" />
<Compile Include="mono\System.Imaging\MetafileTest.cs" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<Compile Include="SurrogateSelectorTests.cs" />
<Compile Include="TargetFrameworkMoniker.cs" />
<Compile Include="TypeSerializableValue.cs" />
<Compile Include="$(CommonTestPath)System\Drawing\Helpers.cs">
<Link>Common\System\Drawing\Helpers.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)System\NonRuntimeType.cs">
<Link>Common\System\NonRuntimeType.cs</Link>
</Compile>
Expand Down

0 comments on commit e1fa5d7

Please sign in to comment.