#1 2025-09-26 16:37:04

tbo
Member
Registered: 2015-04-20
Posts: 375

Check step size before MoveFast

Delphi 12.2
mORMot 2, Commit 2.3.11508

Shouldn't we check whether the content fits in the buffer before using the MoveFast function?

   
procedure TJsonWriter.AddFmt(Format: PUtf8Char; Values: PVarRec; ValuesCount: integer;
  Escape: TTextWriterKind; WriteObjectOptions: TTextWriterWriteObjectOptions);
var
  start: PUtf8Char;
  Len: PtrInt;
begin
  ...
    Len := Format - start;
    if Len <> 0 then
    begin
      if BEnd - B <= Len then  // note: PtrInt(BEnd - B) could be < 0
        FlushToStream;
      MoveFast(start^, B[1], Len);

 
With best regards
Thomas

Offline

#2 2025-09-26 18:50:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,240
Website

Re: Check step size before MoveFast

The Format string is indeed expected to be smaller than the internal buffer size, which is 256 bytes as absolute minimum.

Some Fmt pointer in user code could indeed be bigger than this value.
I have seen people not using a constant, but pointer(anotherString) with a huge pre-calculated value.

Can you create an issue?

Edit:
https://github.com/synopse/mORMot2/issues/390 should be fixed now.

Offline

Board footer

Powered by FluxBB