TFileStream.CopyFrom always fails with "Range check error" on IS6.3

110 views
Skip to first unread message

Krystian Bigaj

unread,
Aug 9, 2024, 9:32:06 AM8/9/24
to innosetup
Hi,

I've an issue with TFileStream and CopyFrom method on IS6.3.3 - it always raise an exception with "Range check error". TFileStream.CopyFrom worked fine on IS5.6.1

I have test function like this:
function FileCopyWithTFileStream(ASrc, ADest: String): Boolean;
var
  lSrc, lDest: TFileStream;
  lSize: Longint;
begin
  Result := True;
  try
    lSrc:= TFileStream.Create(ASrc, fmOpenRead or fmShareDenyNone);
    try
      lDest:= TFileStream.Create(ADest, fmCreate);
      try
        lSize := lSrc.Size;
        lDest.CopyFrom(lSrc, lSize); // size can be any value, 0, 1, lSrc.Size, but always fails with "Range check error". This worked in 5.6.1
      finally
        lDest.Free;
      end;
    finally
      lSrc.Free;
    end;
  except
    Log('FileCopyWithTFileStream failed. Exception=' + GetExceptionMessage);
    Result := False;
  end;
end;

I could not find exact place in code where change was made, but it might be releated to fix (maybe not fixed similar issue in TStream.CopyFrom?):

6.3.2 (2024-06-28)

  • Pascal Scripting change: Fixed support function TStream.Seek.
PS. I'm aware that there is a FileCopy support function, but for some reason it doesn't allow me to copy installer file to other location FileCopy(ExpandConstant('{srcexe}'), always returns False)

-- 
Regards,
Krystian Bigaj



Message has been deleted

Martijn Laan

unread,
Aug 11, 2024, 7:33:44 AM8/11/24
to inno...@googlegroups.com
Hi,

Op 9-8-2024 om 15:31 schreef Krystian Bigaj:
PS. I'm aware that there is a FileCopy support function, but for some reason it doesn't allow me to copy installer file to other location FileCopy(ExpandConstant('{srcexe}'), always returns False)

You can use a regular [Files] section entry to copy the installer file. For example:

[Files]
Source: {srcexe}; DestDir: {app}; Flags: external


I will look into CopyFrom a little later even though I wouldnt recommend using [Code] in this case.

Greetings,
Martijn

NetFilter Test

unread,
Aug 13, 2024, 3:36:42 AM8/13/24
to innosetup
Hi,

Thank you, that "external flag" worked for me.

But I'm curious about that FileCopy vs. {srcexe} - do you remember reason why it was blocked, or why it is not recommended to copy {srcexe} inside [Code] section?

Martijn Laan

unread,
Aug 13, 2024, 3:40:53 AM8/13/24
to inno...@googlegroups.com
It's never recommended to do things in [Code] which can be done in a more 'regular' way, like using [FIles] to handle files instead of [Code].

The blockage is to make it a little more difficult to write self installing malware installers using Inno Setup.

Greetings,
Martijn

Op dinsdag 13 augustus 2024 om 09:16 schreef NetFilter Test <axence.net...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "innosetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to innosetup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/68b56666-4fd9-4743-a40c-91cccfbd2d4cn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages