Bug

A memory overwrite bug has been identified in the TDropFileSource and TDropFileTarget components of the Drag and Drop Component Suite. The bug only manifests itself when support for Unicode filenames is enabled - even if Unicode filenames aren’t used explicitly. Unicode filenames are enabled with Delphi 2006 and later.

Scope

  • Delphi 2006, Delphi 2007
  • The Drag and Drop Component Suite v4.2
  • The Drag and Drop Component Suite v5.0.20080514 (development snapshot)

Cause

The memory overwrite is caused by an incorrect cast in the constructor of the TFileDataFormat class. TFileDataFormat is used internally by components that support drag or drop of files, namely the TDropFileSource, TDropFileTarget, TDropComboTarget and TDropContextMenu components.

The offending code casts a TWideStringList object to a TStringList and sets a property that only exists on the TStringList class:

constructor TFileDataFormat.Create(AOwner: TDragDropComponent);
begin
  inherited Create(AOwner);
  FFiles := TWideStringList.Create;
  TStringList(FFiles).OnChanging := DoOnChanging;
end;

Since the relative offset of the TStringList.OnChanging property is beyond the size of a TWideStringList object, the result is that random memory is being overwritten.

Symptoms

The bug causes a memory overwrite and the exact symptoms will depend on the current memory layout. Common symptoms are Out of Memory, Access Violation and Stack Overflow errors. The error will most like occur when the components are being constructed. For example when a form, that contains one of the affected components, is created.

If the application is compiled with FastMM in debug mode, FastMM should be able to detect the memory overwrite.

Workaround

To avoid the bug, support for Unicode filenames must be disabled. This is best done by disabling or deleting the following line in the DragDrop.inc include file:

{$define DD_WIDESTRINGLIST}

Resolution

The problem has already been fixed in the version 5 branch and a new snapshot will be posted as soon as possible.

For version 4.2 the fix is available as a hotfix. The fix will likely be rolled into a future version 4 release if time permits.

Download

Note: This download only applies to the Drag and Drop Component Suite version 4.2.

download
Download: The Drag and Drop Component Suite - Hotfix 4.2.20080604
Version: 4.2.20080604
Updated: 4 June, 2008
Size: 5.08 KB
Notes: Hotfix for the Drag and Drop Component Suite version 4.2
Fixes a memory overwrite bug in TDropFileSource, TDropFileTarget a.o.
Downloads: 5,196

Installation

  1. Download the hotfix.
  2. Make a backup copy of your existing DropDropFile.pas file.
  3. Extract and copy the new DropDropFile.pas into the Drag and Drop Component Suite source folder.
  4. Rebuild the Drag and Drop Component Suite design package.
  5. Rebuild any applications affected by this bug.