commit c2515a8f2be5dd23354c9891f41ad104000f88c4
Author: Nikita Popov <npopov@redhat.com>
Date:   Tue Sep 26 16:51:40 2023 +0200

    [Bitcode] Add some missing GetTypeByID failure checks

    Print an error instead of crashing.

    Fixes https://github.com/llvm/llvm-project/issues/67388.

Upstream-Status: Backport [https://github.com/llvm/llvm-project/commit/c2515a8f2be5dd23354c9891f41ad104000f88c4]
CVE: CVE-2023-46049
Signed-off-by: Deepthi Hemraj <Deepthi.Hemraj@windriver.com>

--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp	2022-01-20 13:31:59.000000000 -0800
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp	2024-07-28 21:35:31.062992219 -0700
@@ -1235,7 +1235,7 @@
     }
 
     Type *Ty = getTypeByID(Record[0]);
-    if (Ty->isMetadataTy() || Ty->isVoidTy()) {
+    if (!Ty || Ty->isMetadataTy() || Ty->isVoidTy()) {
       dropRecord();
       break;
     }
@@ -1277,7 +1277,7 @@
       return error("Invalid record");
 
     Type *Ty = getTypeByID(Record[0]);
-    if (Ty->isMetadataTy() || Ty->isVoidTy())
+    if (!Ty || Ty->isMetadataTy() || Ty->isVoidTy())
       return error("Invalid record");
 
     MetadataList.assignValue(
