Possible problem in TIdStreamVCLWin32.Write

Giganews Newsgroups
Subject: Possible problem in TIdStreamVCLWin32.Write
Posted by:  Etienne van Tonder (e…@infoware.com.au)
Date: Wed, 11 Aug 2004

My users have received a couple of e-mails that contain a virus attachment
that cause a AV when using TIdMessage Retrieve. I've traced into the code
and found where the AV is being generated, I've added code to prevent the
error from occuring but am unsure if there is an underlying problem that
causes the error.

When doing the Retrieve, TIdMessageDecoderMIME.ReadBody is called, within
the procedure the TIdDecoder4to3.Decode is called. The line marked ****
returns NULL, ie LOut is NULL. The NULL value is then passed to
TIdStreamVCLWin32.Write which generates the AV when
VCLStream.WriteBuffer(ABytes[0], ACount); is executed.

To overcome the problem I've added a check for NULL, see code below. This
problem only exists in one or two messages the users have received, other
messages with virus files seems to be ok. I can send an example message that
generates this problem if required.

procedure TIdDecoder4to3.Decode(const AIn: string; const AStartPos: Integer
= 1; const ABytes: Integer = -1);
var
  LIn : TIdBytes;
  LOut: TIdBytes;
begin
  if AIn <> '' then begin
    SetLength(LIn,  0);  //Stop compiler warning
    SetLength(LOut, 0);  //Stop compiler warning
    LIn := ToBytes(AIn); // if in dotnet, convert to serialisable format
    LOut := InternalDecode(LIn, AStartPos, ABytes);  ****
    // Write out data to stream
    FStream.Write(LOut);
  end;
end;

procedure TIdStreamVCLWin32.Write(const ABytes: TIdBytes; ACount: Integer);
begin
  // EVT: With some messages that contains a virus ABytes is NULL
  // causing an AV when doing the WriteBuffer
  if ABytes <> nil then begin
    if ACount = -1 then begin
      ACount := Length(ABytes);
    end;
    VCLStream.WriteBuffer(ABytes[0], ACount);
  // EVT
  end;
end;

Regards,

Etienne.

Replies