Check if the child object is in the heap range before object_gennum (#63970)
authorAndrew Au <andrewau@microsoft.com>
Thu, 20 Jan 2022 01:59:07 +0000 (17:59 -0800)
committerGitHub <noreply@github.com>
Thu, 20 Jan 2022 01:59:07 +0000 (17:59 -0800)
src/coreclr/gc/gc.cpp

index 8d4f4b4..958a456 100644 (file)
@@ -43430,8 +43430,15 @@ void GCHeap::SetYieldProcessorScalingFactor (float scalingFactor)
 
 unsigned int GCHeap::WhichGeneration (Object* object)
 {
-    gc_heap* hp = gc_heap::heap_of ((uint8_t*)object);
-    unsigned int g = hp->object_gennum ((uint8_t*)object);
+    uint8_t* o = (uint8_t*)object;
+#ifdef FEATURE_BASICFREEZE
+    if (!((o < g_gc_highest_address) && (o >= g_gc_lowest_address)))
+    {
+        return max_generation;
+    }
+#endif //FEATURE_BASICFREEZE
+    gc_heap* hp = gc_heap::heap_of (o);
+    unsigned int g = hp->object_gennum (o);
     dprintf (3, ("%Ix is in gen %d", (size_t)object, g));
     return g;
 }