Off-by-one error in TConnectorFastReadExpr.GetDataPtr

Issue #40 resolved
Anders Melander created an issue

The line EvalAsVariant(exec, resultData[1]); causes a Range Check error.

unit dwsConnectorExprs;
...
procedure TConnectorFastReadExpr.GetDataPtr(exec : TdwsExecution; var result : IDataContext);
var
   resultData : TData;
begin
   SetLength(resultData, 1);
   EvalAsVariant(exec, resultData[1]);
   exec.DataContext_Create(resultData, 0, result);
end;

Comments (6)

  1. Eric Grange repo owner

    This appears to be dead code, did you hit the code at runtime or found the bug by looking at the code? (might make the method as abstract in that case)

  2. Anders Melander reporter

    I encountered it at runtime assigning a JSONVariant member to a Variant.

        ProjectProperties.Values['customer.name'] := Customer.name;
    

    TProjectProperties.Values[] is a Variant.
    Customer is a JSONVariant.
    Customer.name is a string.

    Call stack:

    dwsConnectorExprs.TConnectorFastReadExpr.GetDataPtr($F67F0F0,nil)
    dwsExprs.TPushOperator.ExecuteAddr($F67F0F0)
    dwsExprs.TFuncExpr.DoEvalCall($F67F0F0,$D2B3590)
    dwsMethodExprs.TMethodExpr.EvalAsVariant($F67F0F0,Unassigned)
    dwsMethodExprs.TMethodStaticExpr.EvalAsVariant($F67F0F0,Unassigned) dwsSymbols.TExprBase.EvalNoResult($F67F0F0)

  3. Eric Grange repo owner

    What is the underltying method behind "TProjectProperties.Values[]" ?

    I could reproduce it with a method with a const parameter like "SetValues(const arg : Variant)"

  4. Anders Melander reporter

    TProjectProperties is declared in a TdwsUnit and implemented Delphi side.

    The declaration looks something like:

    TProjectProperties
      procedure SetValue(const Name: string; const Value: Variant);
      property Values[const Name: string]: Variant read GetValue write SetValue;
    

    and this is the implementation of TProjectProperties.SetValue:

      TSigmaProjectPropertySet(ExtObject).Items[Info.ParamAsString[0]] := Info.ParamAsVariant[1];
    
  5. Eric Grange repo owner

    Ok, should be covered by the test case.

    FWIW const parameters are currently executed slowly for simple datatypes (cf. Issue #42)

  6. Log in to comment