RTL: heap allocator can call alloc_oschunk with size=0 which lead to recursive RunError(204)
Original Reporter info from Mantis: AntonK
-
Reporter name: Anton Kavalenka
Original Reporter info from Mantis: AntonK
- Reporter name: Anton Kavalenka
Description:
Recent heap manager changes led to imposibility of callback usage from delphi-compiled dlls to FPC host application code.
Researching brings me some confusion - allocation of memory block of size 0 sometimes brings 4M or 4G block allocation etc.
Heap manager brought to the mentioned state can raise RunError(204), which handling also requires calling Getmem() and subsequently raise RunError(204) until all stack is eaten.
Currently my application ends its life in heap.inc:857, where size gets=0, chunksize obviously non-zero.
if ptruint(size-chunksize)>maxsize then
HandleError(204);
The example shows the simple way to fool heap manager. Please note different behavour of test when specified -32 byte of allocation instead of -128.
Steps to reproduce:
program Project1;
{$mode delphi}{$H+}
var
i:integer;
p:pointer;
begin
for i:=0 to MaxInt do
begin
GetMem(p,-128);
writeln('i=',i,' p=',ptruint(p));
end;
end.
Additional information:
Delphi use signed Size-argument for GetMem.
So requesting negative-sized block returns nil.
Mantis conversion info:
- Mantis ID: 17430
- OS: Windows
- OS Build: 5.1
- Build: 15994
- Platform: i386
- Version: 2.5.1
- Fixed in version: 2.6.0
- Fixed in revision: 16001 (#24201631)