From 81109f0df6e6e974e91577d1c5e66efb47e5c5ba Mon Sep 17 00:00:00 2001 From: Daniel Prado Velasco Date: Sat, 3 Feb 2024 13:32:18 +0100 Subject: [PATCH] Added some protections to TImageManager.ProcessImagesInRTF in case it 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 fddc38b787887804 (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) --- editor/kn_ImagesMng.pas | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/editor/kn_ImagesMng.pas b/editor/kn_ImagesMng.pas index 305dc5c..f53c2e7 100644 --- a/editor/kn_ImagesMng.pas +++ b/editor/kn_ImagesMng.pas @@ -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) @@ -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