Skip to content

Commit

Permalink
Added some protections to TImageManager.ProcessImagesInRTF in case it…
Browse files Browse the repository at this point in the history
… is called incorrectly

Although the bug describe in issue #644 (Export Notes Crash - Error Message and Application Freeze During Text Notes Export )
was fixed in the commit fddc38b (Fixed some bugs related to Export and UNICODE (see details)), this new changes
introduce some controls to avoid the consequences of that bug (a runaway pointer)
  • Loading branch information
dpradov committed Feb 3, 2024
1 parent ceca54a commit 81109f0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions editor/kn_ImagesMng.pas
Expand Up @@ -2762,8 +2762,14 @@ function TImageManager.ProcessImagesInRTF(const Buffer: Pointer; BufSize: intege
In_shppict:= false;


Result:= '';
RTFText:= PAnsiChar(Buffer);

if (assigned(Note) and Note.PlainText) or (Length(RTFText) > BufSize) then begin
assert(Length(RTFText) <= BufSize );
exit;
end;

assert(Length(RTFText) <= BufSize );

// fExtenalImagesManager <> nil : We are processing note images from a file we are merging (see MergeFromKNTFile)
Expand Down Expand Up @@ -3033,6 +3039,11 @@ function TImageManager.ProcessImagesInRTF(const Buffer: Pointer; BufSize: intege

if (fStorageMode <> smEmbRTF) then begin
if (ImgID = 0) and ((ImageMode = imImage) or UseExtenalImagesManager) and (Stream <> nil) and (Stream.Size > 0) then begin
if Note = nil then begin
assert(Note <> nil);
Exit(''); // It shouldn't happen, but if it does, we are exporting notes. We leave without processing anything
end;

if Img <> nil then begin // Processing images from MergeFromKNTFile
ImgCaption:= Img.Caption;
if CheckRegisterImage (Stream, Img.ImageFormat, Width, Height, Note, Img.OriginalPath, Img.IsOwned, 'MergeKNT', Img) then begin
Expand Down

0 comments on commit 81109f0

Please sign in to comment.