TDAMemDataTable, AV when short datString value is put to string field (XE3)

Hello,

I have encountered a serious problem with DataAbstract MemDataTable. When used with Delphi XE3, the fields of type datString causes an AV exception. From the stack trace it seems the problem lies in the TDAMemoryDataset.InternalSetFieldData() method, in which the Move() call takes the defined field size, where the dynamically allocated source buffer can be shorter. I have prepared small sample project to demonstrate the issue.

daSample.zip (80.3 KB)

Regards from Prague,
Jaroslav

*** Stack trace:

System.Move(???,???,???)
uDAMemDataset.TDAMemoryDataset.InternalSetFieldData(???,(86, 97, 108, 117, 101, 32, 35, 51, 50, 48, 56, 51, 0))
uDAMemDataset.TDAMemoryDataset.SetFieldData(???,(86, 97, 108, 117, 101, 32, 35, 51, 50, 48, 56, 51, 0))
Data.DB.TDataSet.SetFieldData($18C9880,(86, 97, 108, 117, 101, 32, 35, 51, 50, 48, 56, 51, 0),True)
Data.DB.TField.SetData((86, 97, 108, 117, 101, 32, 35, 51, 50, 48, 56, 51, 0),True)
Data.DB.TStringField.SetAsAnsiString(???)
Data.DB.TStringField.SetAsString('Value #32083')
uDAFields.TDACustomField.SetAsString(???)
Unit1.TForm1.Button1Click($18F0140)
...

Hello,
Thanks, the issue was logged as #66159.
We will send you a workaround at the nearest time.

Thanks.
We’ve reproduced this problem with default Delphi memory manager.

as a workaround, you can use FastMM4 memory manager. your testcase works without any problem with FastMM4.
also you can add {$SetPEFlags $20} to your dpr. with this, FastMM4 allows to use up to 3GB of user mode address space under Windows 32-bit and 4GB under Windows 64-bit and “for I:= 1 to 1500000 do” loop also works without any problem.

additional way is set memdatatable.AutoCompactRecord to True. it will decrease memory consumption, but can show worse performance, but it still fail with default delphi memory manager.