From 4490bcce57509c84558eb0e9dc6e4a3d111c1e66 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 9 Aug 2023 22:53:36 +0900 Subject: [PATCH] Make ComHost.Create throw InvalidTypeLibraryException if type library is empty file (#90220) --- src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs b/src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs index 03a7276..4dfb778 100644 --- a/src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs +++ b/src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs @@ -11,7 +11,6 @@ namespace Microsoft.NET.HostModel.ComHost { public class ComHost { - private const int E_INVALIDARG = unchecked((int)0x80070057); // These need to match RESOURCEID_CLSIDMAP and RESOURCETYPE_CLSIDMAP defined in comhost.h. private const int ClsidmapResourceId = 64; private const int ClsidmapResourceType = 1024; @@ -61,16 +60,15 @@ namespace Microsoft.NET.HostModel.ComHost try { byte[] tlbFileBytes = File.ReadAllBytes(typeLibrary.Value); + if (tlbFileBytes.Length == 0) + throw new InvalidTypeLibraryException(typeLibrary.Value); + updater.AddResource(tlbFileBytes, "typelib", (IntPtr)typeLibrary.Key); } catch (FileNotFoundException ex) { throw new TypeLibraryDoesNotExistException(typeLibrary.Value, ex); } - catch (HResultException hr) when (hr.Win32HResult == E_INVALIDARG) - { - throw new InvalidTypeLibraryException(typeLibrary.Value, hr); - } } } updater.Update(); -- 2.7.4