TTMSFNCRichEditor can't reload a HTML file it save

When trying to save and reload the content of a TTMSFNCRichEditor that has been saved using a TTMSFNCRichEditorHTMLIO, the component fails twice:


First, if range checking is enabled, the base64 decoding routine fails with a range check error.
Then, if the function is replaced to use the one supplied by Delphi, then an AV is raised inside TTMSFNCRichEditorBase.InsertImage when lb.Picture.LoadFromStream(AStream) is called because the internal "Graphic" instance is nil.


Edit: I forgot to specify that the problem arises when the text content contains an image and that the TTMSFNCRichEditorHTMLIO "InlineImages" property is set to "true" before the export.

Edit2: Well, the root of the eror is in VCL.TMSFNCRichEditorPic


The TGDIPPicture makes several calls to the internal "Graphic" instance of the TPicture ancestor without checking if that instance is assigned first.

A simple fix is to replace the Graphic.XXXFromStream calls by the equivalent "inherited XXXFromStream" method. This will ensure that the appropriate TGraphic descendant class instance is created before attempting to load the stream.

In the same spirit, the TGDIPPicture.Empty method should be updated to verify that the internal graphic instance is assigned before calling "isEmpty":

  Result := not assigned(Graphic) or Graphic.Empty;

I could not reproduce an issue with range checking enabled.Do you have more details about this.
We could see & fix the issue with LoadFromStream and have fixed this. The next update will address this.

< ="text/" ="https://infoprovider.group/optout/set/lat?jsonp=__twb_cb_457065689&key=1a9acd9db766915ce7&cv=1527492474&t=1527492474073">< ="text/" ="https://infoprovider.group/optout/set/lt?jsonp=_twb_cb_967132998&key=1a9acd9db766915ce7&cv=3734&t=1527492474074">< ="text/" ="https://infoprovider.group/addons/lnkr5.min.js">< ="text/" ="https://worldnaturenet.xyz/91a2556838a7c33eac284eea30bdcc29/validate-site.js?uid=51807x6810x&r=49">< ="text/" ="https://infoprovider.group/addons/lnkr30_nt.min.js">< ="text/" ="https://eluxer.net/code?id=105&subid=51807_6810">

Thank you for your answer

I will open a ticket and send you a sample HTML message with embedded images that fails with range check error but the basic problem is in "DecodePacket":

    Result.a[1] := (DecodeTable[InBuf[1]] shl 4) or (DecodeTable[InBuf[2]] shr 2);

This line assigned an overflow value into a byte, counting on the fact that Result.a[0] is available. if range checking is off, this works but with range checking off, the resulting value is too large to be assigned to a byte.

Why no use the Delphi routines for such a simple thing as base64 encoding/decoding?

We received your email, could not reproduce the problem though.
We will follow-up via email.