1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Improvements to coping with malformed JSONB.

FossilOrigin-Name: 563cde404cec4c6559ae0c5fc5edbc878fee874b36562ce2fac5049cc8349343
This commit is contained in:
drh
2023-10-06 00:06:26 +00:00
parent 27401d38d8
commit dd7f09e6c0
3 changed files with 12 additions and 11 deletions

View File

@@ -3512,6 +3512,7 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){
if( !pParse->oom ){
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
}
if( k&1 ) return -1;
break;
}
}
@@ -3724,10 +3725,10 @@ static u32 jsonLookupBlobStep(
k = j+n;
if( k+sz>=iEnd ) return JSON_BLOB_ERROR;
if( sz==nKey && memcmp(&pParse->aBlob[k], zKey, nKey)==0 ){
j = k+sz;
j = k+sz;
if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_BLOB_ERROR;
n = jsonbPayloadSize(pParse, j, &sz);
if( j+n+sz>iEnd ) return JSON_BLOB_ERROR;
if( n==0 || j+n+sz>iEnd ) return JSON_BLOB_ERROR;
return jsonLookupBlobStep(pParse, j, &zPath[i], pzErr);
}
j = k+sz;
@@ -4031,7 +4032,7 @@ static void jsonExtractFromBlob(
}else if( i==JSON_BLOB_NOTFOUND ){
return; /* Return NULL if not found */
}else if( i==JSON_BLOB_ERROR ){
sqlite3_result_error(ctx, "malformed JSONB", -1);
sqlite3_result_error(ctx, "malformed JSON", -1);
}else{
sqlite3_result_error(ctx, zErr, -1);
}
@@ -4340,7 +4341,7 @@ static void jsonExtractFunc(
JsonString jx;
if( argc<2 ) return;
if( sqlite3_value_type(argv[0])==SQLITE_BLOB && argc==2 ){
if( jsonFuncArgMightBeBinary(argv[0]) && argc==2 ){
jsonExtractFromBlob(ctx, argv[0], argv[1], flags);
return;
}