Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2025-11

TFile.ReadAllBytes broken in 3.2.4RC1

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

TFile.ReadAllBytes (in System.IOUtils) seems to alwasy return TBytes filled with zero's.

It's implemented as
(See: https://gitlab.com/freepascal.org/fpc/source/-/blob/fixes_3_2/packages/vcl-compat/src/system.ioutils.pp?ref_type=heads)

class function TFile.ReadAllBytes(const aPath: string): TBytes;
begin
  Result:=[];
  With OpenRead(aPath) do
    try
       SetLength(Result,Size);
       ReadBuffer(Result,0);  << second param should be "Size"
    finally
      Free;
    end;
end;

This is fixed in main.
https://gitlab.com/freepascal.org/fpc/source/-/commit/9eb77599e18c89bbe426bf272233540206893271

I think it's not been merged to fixes branch,

Shoud I file a bugreport about it?

Bart

Reply by email

Bart
to Bart
ReadBuffer(Result,0); << second param should be "Size"

Not sure, but this (ReadBuffer(Result,Size);) seems to crash then (memory corruption)?

This:

     ReadBuffer(Result[0],Size);

seems to work OK though.
(Should be save even if Size is zero, since ReadBuffer does nothing then)

Bart

Reply by email

michael
to Bart
Bart wrote 12 lines
On Sun, Nov 2, 2025 at 1:58 PM Bart wrote: > ReadBuffer(Result,0); << second param should be "Size" Not sure, but this (ReadBuffer(Result,Size);) seems to crash then (memory corruption)? This: ReadBuffer(Result[0],Size); seems to work OK though. (Should be save even if Size is zero, since ReadBuffer does nothing then)

Actually, the ReadBuffer(Result,SIze) is broken due to ReadBuffer(TBytes,Count) being broken.
Compiler does not select the correct overload, but the fix for that has not been backported.
The solution would be to add offset zero.

Michael.

Reply by email

Bart
to michael
Show quoted text 5 lines
Actually, the ReadBuffer(Result,SIze) is broken due to ReadBuffer(TBytes,Count) being broken. Compiler does not select the correct overload, but the fix for that has not been backported. The solution would be to add offset zero.

Should I open a ticket?

Bart

Reply by email

michael
to Bart
Bart wrote 11 lines
On Mon, Nov 3, 2025 at 1:58 AM michael via fpc-devel wrote: > Actually, the ReadBuffer(Result,SIze) is broken due to > ReadBuffer(TBytes,Count) being broken. > Compiler does not select the correct overload, but the fix for that > has > not been backported. > The solution would be to add offset zero. Should I open a ticket?

Yes, please.
Note that AFAIK the compiler fix will not be backported, we just need to fix the call to ReadBuffer.

Michael.

Reply by email