Add an error log to determine where to throw BadImageFormatException 39/195839/1 accepted/tizen/5.0/base/20181221.113757 submit/tizen_5.0_base/20181219.005417
authorWoongsuk Cho <ws77.cho@samsung.com>
Tue, 18 Dec 2018 23:50:43 +0000 (08:50 +0900)
committerWoongsuk Cho <ws77.cho@samsung.com>
Tue, 18 Dec 2018 23:52:52 +0000 (08:52 +0900)
Change-Id: I0231e9c5209ce39acfe37c54cfcda934b4f773db

13 files changed:
src/binder/assembly.cpp
src/binder/assemblybinder.cpp
src/binder/clrprivbinderassemblyloadcontext.cpp
src/binder/clrprivbindercoreclr.cpp
src/utilcode/peinformation.cpp
src/vm/assemblynative.cpp
src/vm/clrex.cpp
src/vm/dllimport.cpp
src/vm/managedmdimport.cpp
src/vm/nativeformatreader.h
src/vm/pefile.cpp
src/vm/runtimehandles.cpp
src/vm/typedesc.cpp

index 8fcc7cf..a275c85 100644 (file)
@@ -191,6 +191,7 @@ Exit:
         if (!fInspectionOnly && !IsValidArchitecture(kAssemblyArchitecture))
         {
             // Assembly image can't be executed on this platform
+            fprintf(stderr, "@@[SR] %s:%d, fInspectionOnly(%d), IsValidArchitecture(%d)\n", __FILE__, __LINE__, fInspectionOnly, IsValidArchitecture(kAssemblyArchitecture));
             IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
         }
 
index 7c0aa80..89f4a06 100644 (file)
@@ -517,6 +517,7 @@ namespace BINDER_SPACE
         {
             // Not a PE. Shouldn't ever get here.
             BINDER_LOG(W("Not a PE!"));
+            fprintf(stderr, "@@[SR] %s:%d, Not a PE\n", __FILE__, __LINE__);
             IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
         }
         else 
@@ -535,6 +536,7 @@ namespace BINDER_SPACE
                 {
                     // Invalid
                     BINDER_LOG(W("CLRPeKind & pe32BitRequired is true"));
+                    fprintf(stderr, "@@[SR] %s:%d, Not a PE\n", __FILE__, __LINE__);
                     IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
                 }
 
@@ -548,6 +550,7 @@ namespace BINDER_SPACE
                 {
                     // We don't support other architectures
                     BINDER_LOG(W("Unknown architecture"));
+                    fprintf(stderr, "@@[SR] %s:%d, Not a PE\n", __FILE__, __LINE__);
                     IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
                 }
             }
@@ -562,6 +565,7 @@ namespace BINDER_SPACE
                 {
                     // Not supported
                     BINDER_LOG(W("32-bit, non-agnostic"));
+                    fprintf(stderr, "@@[SR] %s:%d, Not a PE\n", __FILE__, __LINE__);
                     IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
                 }
             }
@@ -852,6 +856,7 @@ namespace BINDER_SPACE
         // Validate architecture
         if (!fInspectionOnly && !Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture()))
         {
+            fprintf(stderr, "@@[SR] %s:%d, Not a PE\n", __FILE__, __LINE__);
             IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
         }
 
index e6f957a..c6f729d 100644 (file)
@@ -145,6 +145,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pP
         // Validate architecture
         if (!BINDER_SPACE::Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture()))
         {
+            fprintf(stderr, "@@[SR] %s:%d\n");
             IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
         }
         
index d756454..2c1b9bd 100644 (file)
@@ -136,6 +136,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage,
         // Validate architecture
         if (!BINDER_SPACE::Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture()))
         {
+            fprintf(stderr, "@@[SR] %s:%d\n");
             IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
         }
         
index 20a9fe1..de7bbc6 100644 (file)
@@ -26,6 +26,7 @@ HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DW
     if (CLRPeKind == peNot)
     {   // Not a PE. Shouldn't ever get here.
         *pPeKind = peInvalid;
+        fprintf(stderr, "@@[SR] %s:%d\n");
         hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
         goto Exit;
     }
@@ -51,6 +52,7 @@ HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DW
             if (CLRPeKind & pe32BitRequired)
             {
                 *pPeKind = peInvalid;
+                fprintf(stderr, "@@[SR] %s:%d\n");
                 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
                 goto Exit;
             }
@@ -69,6 +71,7 @@ HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DW
             else
             {   // We don't support other architectures
                 *pPeKind = peInvalid;
+                fprintf(stderr, "@@[SR] %s:%d\n");
                 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
                 goto Exit;
             }
@@ -88,6 +91,7 @@ HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DW
             else
             {   // Not supported
                 *pPeKind = peInvalid;
+                fprintf(stderr, "@@[SR] %s:%d\n");
                 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
                 goto Exit;
             }
index f0cfe93..5929541 100644 (file)
@@ -233,6 +233,7 @@ Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImag
         
         StackSString name;
         spec.GetFileOrDisplayName(0, name);
+        fprintf(stderr, "@@[SR] %s:%d\n");
         COMPlusThrowHR(COR_E_FILELOAD, dwMessageID, name);
     }
 
index 930ac5d..a67dbef 100644 (file)
@@ -1837,7 +1837,10 @@ RuntimeExceptionKind EEFileLoadException::GetFileLoadKind(HRESULT hr)
             (hr == COR_E_LOADING_REFERENCE_ASSEMBLY) ||
             (hr == META_E_BAD_SIGNATURE) || 
             (hr == COR_E_LOADING_WINMD_REFERENCE_ASSEMBLY))
+        {
+            fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
             return kBadImageFormatException;
+        }
         else 
         {
             if ((hr == E_OUTOFMEMORY) || (hr == NTE_NO_MEMORY))
index d019631..7cfb5cb 100644 (file)
@@ -5786,6 +5786,7 @@ public:
         HRESULT theHRESULT = GetHR();
         if (theHRESULT == HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT))
         {
+            fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, theHRESULT);
             COMPlusThrow(kBadImageFormatException);
         }
         else
index e780275..0bc5ea2 100644 (file)
@@ -127,6 +127,7 @@ ErrExit:
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrow(kBadImageFormatException);
     }
     
@@ -149,6 +150,7 @@ ErrExit:
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -280,6 +282,7 @@ ErrExit:
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -318,6 +321,7 @@ ErrExit:
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrow(kBadImageFormatException);
     }
     FC_RETURN_BOOL(retVal);
@@ -338,6 +342,7 @@ MDImpl3(void, MetaDataImport::GetUserString, mdToken tk, LPCSTR* pszName, ULONG*
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -390,6 +395,7 @@ MDImpl2(void, MetaDataImport::GetName, mdToken tk, LPCSTR* pszName)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -409,6 +415,7 @@ MDImpl2(void, MetaDataImport::GetNamespace, mdToken tk, LPCSTR* pszName)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -428,6 +435,7 @@ MDImpl2(void, MetaDataImport::GetGenericParamProps, mdToken tk, DWORD* pAttribut
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -446,6 +454,7 @@ MDImpl3(void, MetaDataImport::GetEventProps, mdToken tk, LPCSTR* pszName, INT32
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -476,6 +485,7 @@ MDImpl4(void, MetaDataImport::GetPinvokeMap, mdToken tk, DWORD* pMappingFlags, L
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -507,6 +517,7 @@ MDImpl3(void, MetaDataImport::GetParamDefProps, mdToken tk, INT32* pSequence, IN
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -525,6 +536,7 @@ MDImpl2(void, MetaDataImport::GetFieldDefProps, mdToken tk, INT32 *pdwFieldFlags
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -543,6 +555,7 @@ MDImpl4(void, MetaDataImport::GetPropertyProps, mdToken tk, LPCSTR* pszName, INT
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -567,6 +580,7 @@ MDImpl2(void, MetaDataImport::GetFieldMarshal, mdToken tk, ConstArray* ppValue)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -585,6 +599,7 @@ MDImpl2(void, MetaDataImport::GetSigOfMethodDef, mdToken tk, ConstArray* ppValue
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -603,6 +618,7 @@ MDImpl2(void, MetaDataImport::GetSignatureFromToken, mdToken tk, ConstArray* ppV
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -621,6 +637,7 @@ MDImpl2(void, MetaDataImport::GetSigOfFieldDef, mdToken tk, ConstArray* ppValue)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -670,6 +687,7 @@ MDImpl2(void, MetaDataImport::GetParentToken, mdToken tk, mdToken* ptk)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -689,6 +707,7 @@ MDImpl1(void, MetaDataImport::GetScopeProps, GUID* pmvid)
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
@@ -711,6 +730,7 @@ MDImpl2(void, MetaDataImport::GetMemberRefProps,
     
     if (FAILED(hr))
     {
+        fprintf(stderr, "@@[SR] %s:%d, exception number(%ld)\n", __FILE__, __LINE__, hr);
         FCThrowVoid(kBadImageFormatException);
     }
 }
index 4182b03..fdeadfe 100644 (file)
@@ -54,35 +54,50 @@ namespace NativeFormat
         uint EnsureOffsetInRange(uint offset, uint lookAhead)
         {
             if ((int)offset < 0 || offset + lookAhead >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
             return offset;
         }
 
         byte ReadUInt8(uint offset)
         {
             if (offset >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
             return *(_base + offset); // Assumes little endian and unaligned access
         }
 
         UInt16 ReadUInt16(uint offset)
         {
             if ((int)offset < 0 || offset + 1 >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
             return *dac_cast<PTR_USHORT>(_base + offset); // Assumes little endian and unaligned access
         }
 
         UInt32 ReadUInt32(uint offset)
         {
             if ((int)offset < 0 || offset + 3 >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
             return *dac_cast<PTR_UINT32>(_base + offset); // Assumes little endian and unaligned access
         }
 
         uint DecodeUnsigned(uint offset, uint * pValue)
         {
             if (offset >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
 
             uint val = *(_base + offset);
             if ((val & 1) == 0)
@@ -94,7 +109,10 @@ namespace NativeFormat
             if ((val & 2) == 0)
             {
                 if (offset + 1 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 2) | 
                       (((uint)*(_base + offset + 1)) << 6);
                 offset += 2;
@@ -103,7 +121,10 @@ namespace NativeFormat
             if ((val & 4) == 0)
             {
                 if (offset + 2 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 3) |
                       (((uint)*(_base + offset + 1)) << 5) |
                       (((uint)*(_base + offset + 2)) << 13);
@@ -113,7 +134,10 @@ namespace NativeFormat
             if ((val & 8) == 0)
             {
                 if (offset + 3 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 4) |
                       (((uint)*(_base + offset + 1)) << 4) |
                       (((uint)*(_base + offset + 2)) << 12) |
@@ -128,6 +152,7 @@ namespace NativeFormat
             }
             else
             {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
             }
 
@@ -137,7 +162,10 @@ namespace NativeFormat
         int DecodeSigned(uint offset, int * pValue)
         {
             if (offset >= _size)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
+            }
 
             int val = *(_base + offset);
             if ((val & 1) == 0)
@@ -148,7 +176,10 @@ namespace NativeFormat
             else if ((val & 2) == 0)
             {
                 if (offset + 1 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 2) |
                     (((int)*(_base + offset + 1)) << 6);
                 offset += 2;
@@ -156,7 +187,10 @@ namespace NativeFormat
             else if ((val & 4) == 0)
             {
                 if (offset + 2 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 3) |
                     (((int)*(_base + offset + 1)) << 5) |
                     (((int)*(_base + offset + 2)) << 13);
@@ -165,7 +199,10 @@ namespace NativeFormat
             else if ((val & 8) == 0)
             {
                 if (offset + 3 >= _size)
+                {
+                    fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                     ThrowBadImageFormatException();
+                }
                 *pValue = (val >> 4) |
                     (((int)*(_base + offset + 1)) << 4) |
                     (((int)*(_base + offset + 2)) << 12) |
@@ -179,6 +216,7 @@ namespace NativeFormat
             }
             else
             {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
             }
 
@@ -220,6 +258,7 @@ namespace NativeFormat
             }
             else
             {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 ThrowBadImageFormatException();
                 return offset;
             }
@@ -450,12 +489,18 @@ namespace NativeFormat
 
             int numberOfBucketsShift = (int)(header >> 2);
             if (numberOfBucketsShift > 31)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 _pReader->ThrowBadImageFormatException();
+            }
             _bucketMask = (uint)((1 << numberOfBucketsShift) - 1);
 
             byte entryIndexSize = (byte)(header & 3);
             if (entryIndexSize > 2)
+            {
+                fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__);
                 _pReader->ThrowBadImageFormatException();
+            }
             _entryIndexSize = entryIndexSize;
         }
 
index 77c99f6..a3281c9 100644 (file)
@@ -250,6 +250,7 @@ static void ValidatePEFileMachineType(PEFile *peFile)
         else
             name = StackSString(SString::Utf8, peFile->GetSimpleName());
 
+        fprintf(stderr, "@@[SR] %s:%d, name(%s)\n", __FILE__, __LINE__, name.GetUnicode());
         COMPlusThrow(kBadImageFormatException, IDS_CLASSLOAD_WRONGCPU, name.GetUnicode());
     }
 
index de9505a..e393c14 100644 (file)
@@ -1339,6 +1339,7 @@ FCIMPL1(ReflectClassBaseObject*, RuntimeTypeHandle::GetDeclaringType, ReflectCla
     if (FAILED(typeHandle.GetModule()->GetMDImport()->GetNestedClassProps(tkTypeDef, &tkTypeDef)))
     {
         fThrowException = TRUE;
+        fprintf(stderr, "@@[SR] %s:%d\n");
         reKind = kBadImageFormatException;
         argName = NULL;
         goto Exit;
@@ -2664,6 +2665,7 @@ FCIMPL1(LPCUTF8, RuntimeFieldHandle::GetUtf8Name, FieldDesc *pField) {
     
     if (FAILED(pField->GetName_NoThrow(&szFieldName)))
     {
+        fprintf(stderr, "@@[SR] %s:%d\n");
         FCThrow(kBadImageFormatException);
     }
     return szFieldName;
@@ -2813,6 +2815,7 @@ FCIMPL1(INT32, AssemblyHandle::GetToken, AssemblyBaseObject* pAssemblyUNSAFE) {
     {
         if (FAILED(mdImport->GetAssemblyFromScope(&token)))
         {
+            fprintf(stderr, "@@[SR] %s:%d\n");
             FCThrow(kBadImageFormatException);
         }
     }
index 7da1c84..9b54e02 100644 (file)
@@ -1782,6 +1782,7 @@ LoadConstraintOnOpenType:
 
             default:
             {
+                fprintf(stderr, "@@[SR] %s:%d\n");
                 COMPlusThrow(kBadImageFormatException);
             }
         }