#1 2022-04-08 01:21:48

xwg
Member
Registered: 2021-02-25
Posts: 9

TDocVariantData InitJson cause av when input a illegal json

I use a rawjson as interface base service input param, a illegal json will crash the program. 

test code:

const
  vJson = '{"id": 1, "name": ''Tom''}';  //<- illegal json
var
  v: TDocVariantData;
begin
  writeln(vJson,' is good json:',IsValidJson(vJson));
  if v.InitJSON(vJson, JSON_OPTIONS_FAST) then  //<- cause av
    writeln(v.I['id'], '  ', v.U['name'])
  else
    writeln('bad json');
end.
{"id": 1, "name": 'Tom'} is good json:TRUE
An unhandled exception occurred at $000000010004AC53:
EAccessViolation: Access violation
  $000000010004AC53  InitJsonInPlace,  line 5357 of ../../src/core/mormot.core.variants.pas
  $000000010004AD69  InitJson,  line 5381 of ../../src/core/mormot.core.variants.pas
  $0000000100001B75  main,  line 27 of project1.lpr

Offline

#2 2022-04-08 06:46:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TDocVariantData InitJson cause av when input a illegal json

You are right.
Error should be fixed by https://github.com/synopse/mORMot2/commit/9d929d33

Note that IsValidJson() is with strict=false by default, meaning a single quote is allowed for values.
IsValidJson(vJson, true) returns false as expected.

I have added extended/non-standard 'text' single quoted content as (extended) JSON value input, so that IsValidJson() is coherent with our value.
Now your input would be allowed, and allow 'Tom' as value - since we support JSON with some extension.
See https://github.com/synopse/mORMot2/commit/28f4baa9

Offline

#3 2022-04-09 00:39:15

xwg
Member
Registered: 2021-02-25
Posts: 9

Re: TDocVariantData InitJson cause av when input a illegal json

Great, more and more stable. Thank you.

Offline

Board footer

Powered by FluxBB