فهرست منبع

* tinyheap: Early check for very big requested mem sizes in order to prevent overflows and properly report the out of memory error.

git-svn-id: trunk@45844 -
yury 5 سال پیش
والد
کامیت
6edbc9ed7e
1فایلهای تغییر یافته به همراه5 افزوده شده و 0 حذف شده
  1. 5 0
      rtl/inc/tinyheap.inc

+ 5 - 0
rtl/inc/tinyheap.inc

@@ -57,6 +57,7 @@
 
     const
       TinyHeapMinBlock = sizeof(TTinyHeapBlock);
+      TinyHeapMaxBlock = High(ptruint) - sizeof(TTinyHeapBlock) - sizeof(TTinyHeapMemBlockSize);
 
       TinyHeapAllocGranularity = sizeof(TTinyHeapBlock);
 
@@ -96,6 +97,8 @@
 {$ifdef DEBUG_TINY_HEAP}
         Write('SysGetMem(', Size, ')=');
 {$endif DEBUG_TINY_HEAP}
+        if size>TinyHeapMaxBlock then
+          HandleError(203);
         AllocSize := align(size+sizeof(TTinyHeapMemBlockSize), TinyHeapAllocGranularity);
 
         p := FreeList;
@@ -320,6 +323,8 @@
             if (TTinyHeapPointerArithmeticType(p) < TTinyHeapPointerArithmeticType(HeapOrg)) or
                (TTinyHeapPointerArithmeticType(p) >= TTinyHeapPointerArithmeticType(HeapPtr)) then
               HandleError(204);
+            if size>TinyHeapMaxBlock then
+              HandleError(203);
             oldsize := FindSize(p);
             OldAllocSize := align(oldsize+sizeof(TTinyHeapMemBlockSize), TinyHeapAllocGranularity);
             NewAllocSize := align(size+sizeof(TTinyHeapMemBlockSize), TinyHeapAllocGranularity);