We were testing our CEF4Delphi-based embedded browser on slack.com, trying to upload a local file from the attachment command, when it crashed with a range check error, here:
Code: Select all
function cef_dialog_handler_on_file_dialog(self: PCefDialogHandler; browser: PCefBrowser;
mode: TCefFileDialogMode; const title, default_file_path: PCefString;
accept_filters: TCefStringList; selected_accept_filter: Integer;
callback: PCefFileDialogCallback): Integer; stdcall;
var
list: TStringList;
i: Integer;
str: TCefString;
begin
list := TStringList.Create;
try
for i := 0 to cef_string_list_size(accept_filters) - 1 do
The best fix is to update the declaration of cef_string_list_size in uCEFLibFunctions.pas, like this:
Code: Select all
// cef_string_list_size : function(list: TCefStringList): NativeUInt; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF};
// HV: Changed NativeUInt to Integer to avoid range error when using for i := 0 to cef_string_list_size(X)-1 and size is 0
cef_string_list_size : function(list: TCefStringList): Integer; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF};
This change allows us to keep the clean, logical for loop. I can see that this probably has tripped up code elsewhere that uses this function, as it has been written as a clunky while-do loop, for instance:
uCEFMiscFunctions.pas, CefStringListToStringList:
Code: Select all
procedure CefStringListToStringList(var aSrcSL : TCefStringList; var aDstSL : TStrings);
var
i, j : NativeUInt;
TempString : TCefString;
begin
if (aSrcSL <> nil) and (aDstSL <> nil) then
begin
i := 0;
j := pred(cef_string_list_size(aSrcSL));
while (i < j) do
begin
FillChar(TempString, SizeOf(TempString), 0);
cef_string_list_value(aSrcSL, i, @TempString);
aDstSL.Add(CefStringClearAndGet(TempString));
inc(i);
end;
end;
end;
/Hallvard