From 7b18d3551cf2bdd5ceb9567fed4b5d8f55b7d56b Mon Sep 17 00:00:00 2001 From: Shreya Rao Date: Thu, 20 Nov 2025 09:14:13 +0000 Subject: [PATCH] Fix incorrect fread return value check in ilasm strong-name key loading Summary This PR fixes a logic error in AsmMan::EndAssembly() that incorrectly treated a successful fread() call as a failure. The incorrect condition: ``` dwBytesRead = fread(m_sStrongName.m_pbPublicKey, 1, m_sStrongName.m_cbPublicKey, fp)) <= m_sStrongName.m_cbPublicKey) ``` causes the error branch to execute even when the full key file has been read successfully (dwBytesRead == m_sStrongName.m_cbPublicKey). This results in ilasm failing to read .snk key files when building TestILAssembly on big Endian Systems. Environment: Architecture: s390x OS: Ubuntu Runtime : Mono cc: @uweigand @giritrivedi @saitama951 --- src/coreclr/ilasm/asmman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/ilasm/asmman.cpp b/src/coreclr/ilasm/asmman.cpp index 1f343066c5a36a..d63e8c4457d650 100644 --- a/src/coreclr/ilasm/asmman.cpp +++ b/src/coreclr/ilasm/asmman.cpp @@ -437,7 +437,7 @@ void AsmMan::EndAssembly() // Read the file into the buffer. size_t dwBytesRead; - if ((dwBytesRead = fread(m_sStrongName.m_pbPublicKey, 1, m_sStrongName.m_cbPublicKey, fp)) <= m_sStrongName.m_cbPublicKey) { + if ((dwBytesRead = fread(m_sStrongName.m_pbPublicKey, 1, m_sStrongName.m_cbPublicKey, fp)) < m_sStrongName.m_cbPublicKey) { HRESULT hr = HRESULTFromErrno(); MAKE_UTF8PTR_FROMWIDE(keySourceNameUtf8, ((Assembler*)m_pAssembler)->m_wzKeySourceName); report->error("Failed to read key file '%s': 0x%d\n",keySourceNameUtf8,hr);