MaskEdit: fix potential crash in ApplyMaskToText, that only worked because of implementation details of the internal GetCodePoint function.

This commit is contained in:
Bart 2022-10-04 10:37:44 +02:00
parent 4fda5f9771
commit 79c009420a

View File

@ -1813,29 +1813,37 @@ begin
begin//FMaskSave = False begin//FMaskSave = False
if FTrimType = metTrimRight then if FTrimType = metTrimRight then
begin begin
//fill text from left to rigth, skipping MaskLiterals //while GetCodePoint does not crash on an empty string (and it does not return a #32), it sort of worked by accident in that scenario
j := 1; //and it crashed in similar function in MaskUtils because of that, see: https://forum.lazarus.freepascal.org/index.php/topic,60803.0.html
for i := 1 to FMaskLength do if (Value <> '') then
begin begin
if not IsLiteral(i) then //fill text from left to rigth, skipping MaskLiterals
j := 1;
for i := 1 to FMaskLength do
begin begin
if (GetCodePoint(Value,j) = #32) then SetCodePoint(S,i,FSpaceChar) else SetCodePoint(S,i, GetCodePoint(Value,j)); if not IsLiteral(i) then
Inc(j); begin
if j > Utf8Length(Value) then Break; if (GetCodePoint(Value,j) = #32) then SetCodePoint(S,i,FSpaceChar) else SetCodePoint(S,i, GetCodePoint(Value,j));
Inc(j);
if j > Utf8Length(Value) then Break;
end;
end; end;
end; end;
end end
else else
begin begin
//fill text from right to left, skipping MaskLiterals //fill text from right to left, skipping MaskLiterals
j := Utf8Length(Value); if (Value <> '') then
for i := FMaskLength downto 1 do
begin begin
if not IsLiteral(i) then j := Utf8Length(Value);
for i := FMaskLength downto 1 do
begin begin
if (GetCodePoint(Value,j) = #32) then SetCodePoint(S,i,FSpaceChar) else SetCodePoint(S,i, GetCodePoint(Value,j)); if not IsLiteral(i) then
Dec(j); begin
if j < 1 then Break; if (GetCodePoint(Value,j) = #32) then SetCodePoint(S,i,FSpaceChar) else SetCodePoint(S,i, GetCodePoint(Value,j));
Dec(j);
if j < 1 then Break;
end;
end; end;
end; end;
end; end;