You are not logged in.
Pages: 1
Great, more and more stable. Thank you.
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
@ab need use tmp.InitZero to replace tmp.Init, Otherwise StrLen return is not correct.
maybe can fix this issure
tmp.InitZero(length(utf16) * 3); //<- tmp.Init(length(utf16) * 3);
CharToOemBuffW(pointer(utf16), tmp.buf, length(utf16)); //<- CharToOemBuffW(pointer(utf16), tmp.buf, tmp.len);
Hi ab, thank you for your reply.
I found my program crash when TSynlog EchoToConsole active, debug crash at Utf8ToConsole function, here is reproduce code:
runing in windows10 Simplified Chinese, cp_936.
program project1;
{$codepage utf8}
{$I mormot.defines.inc}
uses
{$I mormot.uses.inc}
SysUtils,
mormot.core.base,
mormot.core.os;
var s: RawByteString;
begin
try
//AV occur
s:=Utf8ToConsole('{"code":2000,"message":"成功","data":{"uuid":"A0D3BB6F-24C6-4E51-80AE-20ECC5A906B9","img":"iVBORw0KGgoAAAANSUhEUgAAAG4AAAAmCAIAAACqMjmtAAADnUlEQVR4nO2aPXaEIBDHuQ5X4Spew5LSK1BaegXLlFumTblHMOgA8i2D+PL2hXnkbaLrOPvb/wwDhpCR9NFmyJ+1223rKJtZR9nMOspm1lE2s46ymXWUzcxC+TXQjRBn0OFLnuAsfhxnfBrJaI+JV8YsBp7u7Kq9nt4psY0ph5xFD5/mq1J8U+BFv4VzA32cvfDRLYICPi6U03kCoFQse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e.message);
end;
end.
param with noascii character will cause Utf8ToConsole crashes program, using FPC_3.2.0+mOrmot2。
writeln(Utf8ToConsole('{"code":2000,"message":"获取校验码成功","data":{"uuid":"A0D3BB6F-24C6-4E51-80AE-20ECC5A906B9","img":"iVBORw0KGgoAAAANSUhEUgAAAG4AAAAmCAIAAACqMjmtAAADnUlEQVR4nO2aPXaEIBDHuQ5X4Spew5LSK1BaegXLlFumTblHMOgA8i2D+PL2hXnkbaLrOPvb/wwDhpCR9NFmyJ+1223rKJtZR9nMOspm1lE2s46ymXWUzcxC+TXQjRBn0OFLnuAsfhxnfBrJaI+JV8YsBp7u7Kq9nt4psY0ph5xFD5/mq1J8U+BFv4VzA32cvfDRLYICPi6U03kCoFQseHcZlLtPvMPAOPO+9sLhJviLxVCK4V3LcZ2ZxxFM82VzxQf1NXEJEQ8l0N0u11CLdgwkhvLAeToBSf7U5I7Oaz4E+tOnsDnJGR/sb0U6CQVaEao2SHGX2hXHNYnyUKUCCkfeTvSlFqa2bTrNTRVOuUkveUfgWBFa0kKSskzS64+fQwluzFxTE5XgqZpoz2OXuwTOlctAD1W2KYthzB7JMo7rFUqnRFYAhRRWCnLbAFdcmBxfhmbTS8QckvsfZRzXPEr+Q8ISGYo0mX0uu9jdl4EnK2ki3OP9B3khqH0//PQVM4tkQXn0YkuhfNNUF5nJPpednruTpAzKonlcKXFmVHDZD1Gr/PJpD4XGCjLKoHmUAFV3WSzJNYPSGem5Oyu9S5Rn355H6WT0zMjerTi9i2k272lTkWR7eRxYvBPPBJlGyV6qVtrCTLGLVdIGKAFa2PQZs+92d7WjFzSHFkGXCFlezeCBSC/cOZUUgRJeto1s26m4kumFpK2UgQnG1SFHyvICZfW6G64JZ5XE0mIDiFZYFXP0vtwjIzX3QpL10WFledlXWsLErHZSCzL3XQsQlxBt2dY2Oj5K7NW+CJGyLEC5RiqmsTwy1aKfzaQ6DxqUR3QFUBWuQIwwvUR5AUpM/+JcHEgQUDbpK8ODRpgJlQVmFo4wdCKremrOTvNaKEa51BkTfQ+c4lUL3BhJbIaXocwKM2uqcwSCRzVcjEi5XlYiKqNCGZEedOx1raWOzutAcBleiLKyYu5Rggx1FksXZmFuUh7j70jwiPRuFUqjScPUjHJZlm792nvs5buWalKGRD4uFquX9RN+u+Sg5vSPwLG6P0+pb89wj2zGS8kDidgSCLnntqez/0DC36nEAYWG3Iw7JfK0U4CpxxIZoI8/JgsBSYj2Iuf4/WR6Z0/vb+1ZlCFEVRm9mX2KZObHAX0KpQcinF7OfI9usFt+msf2kD2CMhRjG7fl/5z3F0/226P8IB21tZYoP666tbXHZ/D/Yx1lM+som5lC2UeT8QtS0NGYb+V8RgAAAABJRU5ErkJggg=="}}'));
It look like it is zeoslib bug in ZDbcInterbase6Statement in line 373, when ArrayCount mod FMaxRowsPerBatch = 0, av occure.
if (ArrayCount <> FMaxRowsPerBatch) and (FBatchStmts[False].PreparedRowsOfArray <> (ArrayCount mod FMaxRowsPerBatch)) then
PrepareFinalChunk(ArrayCount mod FMaxRowsPerBatch); //final block of batch
change to
if (ArrayCount <> FMaxRowsPerBatch) and (ArrayCount mod FMaxRowsPerBatch > 0) and (FBatchStmts[False].PreparedRowsOfArray <> (ArrayCount mod FMaxRowsPerBatch)) then
PrepareFinalChunk(ArrayCount mod FMaxRowsPerBatch); //final block of batch
it look like ok
yes, here is a wrong "EXECUTE BLOCK"
2021-02-26T11:37:24.5850 (20584:0000000000F30040) FREE_STATEMENT
D:\TEST4\TEST.FDB (ATT_64, SYSDBA:NONE, UTF8, TCPv4:127.0.0.1/64026)
/mnt/d/test4/bin/fpc-linux64-Debug/project1:127
Statement 35:
-------------------------------------------------------------------------------
EXECUTE BLOCK(P0_0 VARCHAR(10) CHARACTER SET UTF8 = ?,P1_0 DECIMAL(18,4)=?,P2_0 DECIMAL(18,4)=?,P3_0 DECIMAL(18,4)=?,P4_0 DECIMAL(18,4)=?,P5_0 DECIMAL(18,4)=?,P6_0 DECIMAL(18,4)=?,P7_0 DECIMAL(18,4)=?,P8_0 BIGINT=?,P0_1 VARCHAR(10) CHARACTER SET UTF8 = ?,P1_1 DECIMAL(18,4)=?,P2_1 DECIMAL(18,4)=?,...
2021-02-26T11:37:24.5860 (20584:0000000000F30040) FAILED PREPARE_STATEMENT
D:\TEST4\TEST.FDB (ATT_64, SYSDBA:NONE, UTF8, TCPv4:127.0.0.1/64026)
/mnt/d/test4/bin/fpc-linux64-Debug/project1:127
(TRA_88, READ_COMMITTED | REC_VERSION | NOWAIT | READ_WRITE)
-------------------------------------------------------------------------------
EXECUTE BLOCK(P0_0 VARCHAR( //error here
0 ms
I have a rest service writed with mORMot1.18_lastest+zeoslib7.2.10+firebird3.0.7, compile with Lazarus2.0.12+fpc3.2.0 target linux-x64. I found a weird problem may crash service sometimes at batchsend , I can't figure out where is wrong, There is a test program to reproduce the error: download it
function write_TodayHQ_batch(fContent: variant): boolean;
var
aTodayHQ: TSQLTTodayHQ;
aBatch: TSQLRestBatch;
iLoop : Integer;
v: Variant;
begin
Result := False;
with _safe(fContent)^ do
begin
aBatch := TSQLRestBatch.Create(aRestServer, TSQLTTodayHQ, 200); //200 will error, change to 1000 everything ok
try
for iLoop := 0 to Count - 1 do
begin
v := Values[iLoop];
with _safe(v)^ do
begin
aTodayHQ := TSQLTTodayHQ.Create(aRestServer, 'FCode=?', [U['Code']]);
try
aTodayHQ.FCode := U['Code'];
aTodayHQ.FPClose := D['PClose'];
aTodayHQ.FOpen := D['Open'];
aTodayHQ.FClose := D['Close'];
aTodayHQ.FHigh := D['High'];
aTodayHQ.FLow := D['Low'];
aTodayHQ.FVolume := I['Volume'];
aTodayHQ.FAmount := D['Amount'];
if aTodayHQ.ID > 0 then
aBatch.Update(aTodayHQ)
else
aBatch.Add(aTodayHQ, True);
finally
aTodayHQ.Free;
end;
end;
end;
Result := (aRestServer.BatchSend(aBatch) = HTTP_SUCCESS);
finally
aBatch.Reset;
aBatch.Free;
end;
end;
end;
20210225 03082838 trace mORMotSQLite3.TSQLRestServerDB(7faccc592c10) BatchSend {"TSQLRestBatch(7faccc5ca140)":{"Count":594,"SizeBytes":83991}}
20210225 03082838 + mORMotSQLite3.TSQLRestServerDB(7faccc592c10).EngineBatchSend TSQLTTodayHQ inlen=83992
20210225 03082838 + SynDBZeos.TSQLDBZEOSConnection(7faccc5c9dc0).StartTransaction
20210225 03082838 - 00.000.351
20210225 03082838 DB SynDBZeos.TSQLDBZEOSStatement(7faccc529520) Prepare 968us update TTodayHQ set FCode=?,FPClose=?,FOpen=?,FClose=?,FHigh=?,FLow=?,FVolume=?,FAmount=? where ID=?
20210225 03082843 SQL SynDBZeos.TSQLDBZEOSStatement(7faccc529520) ExecutePrepared 79.58ms wr=200 update TTodayHQ set FCode='SZ300326',FPClose=11.25,FOpen=11.2,FClose=11.33,FHigh=11.64,FLow=11.09,FVolume=0,FAmount=208098038 where ID=3116
20210225 03082844 + SynDBZeos.TSQLDBZEOSConnection(7faccc5c9dc0).StartTransaction
20210225 03082844 - 00.000.034
20210225 03082845 SQL SynDBZeos.TSQLDBZEOSStatement(7faccc529520) ExecutePrepared 14.06ms wr=200 update TTodayHQ set FCode='SZ300530',FPClose=18.34,FOpen=18.3,FClose=18.54,FHigh=19.28,FLow=18.06,FVolume=0,FAmount=28962745 where ID=3316
20210225 03082847 + SynDBZeos.TSQLDBZEOSConnection(7faccc5c9dc0).StartTransaction
20210225 03082847 - 00.000.033
20210225 03082847 EXC EZSQLException ("SQL Error: Dynamic SQL ErrorSQL error code = -104Unexpected end of command - line 1, column 27. Error Code: -104. Invalid token The SQL: EXECUTE BLOCK(P0_0 VARCHAR(; ") [] at $0000000000841AB8 CHECKINTERBASE6ERROR, line 902 of ../FPC/zeoslib7.2/src/dbc/ZDbcInterbase6Utils.pas $0000000000841EED PREPARESTATEMENT, line 956 of ../FPC/zeoslib7.2/src/dbc/ZDbcInterbase6Utils.pas $0000000000853670 PREPARE, line 344 of ../FPC/zeoslib7.2/src/dbc/ZDbcInterbase6Statement.pas $000000000050F44B INTERNALBATCHSTOP, line 1153 of ../FPC/mORMot/SQLite3/mORMotDB.pas $0000000000669B5F PERFORMAUTOMATICCOMMIT, line 42979 of ../FPC/mORMot/SQLite3/mORMot.pas
20210225 03082860 EXC EORMException {"Message":"TSQLRestStorageExternal.InternalBatchStop(TSQLTTodayHQ).BatchMethod=mNone"} [] at $000000000050EB3D INTERNALBATCHSTOP, line 1057 of ../FPC/mORMot/SQLite3/mORMotDB.pas $000000000066967F ENGINEBATCHSEND, line 43225 of ../FPC/mORMot/SQLite3/mORMot.pas
20210225 03082862 trace mORMotSQLite3.TSQLRestServerDB(7faccc592c10) EngineBatchSend json=82 KB add=0 update=594 delete=0 TSQLTTodayHQ
Pages: 1