From: anatawa12 Date: Wed, 9 Aug 2023 13:53:36 +0000 (+0900) Subject: Make ComHost.Create throw InvalidTypeLibraryException if type library is empty file... X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~418 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4490bcce57509c84558eb0e9dc6e4a3d111c1e66;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Make ComHost.Create throw InvalidTypeLibraryException if type library is empty file (#90220) --- 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();