diff options
author | drh <> | 2023-12-02 21:39:34 +0000 |
---|---|---|
committer | drh <> | 2023-12-02 21:39:34 +0000 |
commit | c78c3c91ae722722b0f9ba59dd850885b5ffe5a4 (patch) | |
tree | d7bc5f1045b0a60fbcbabbfd9525576219d28667 /src/json.c | |
parent | 8f8d481485b6409b739a2a5b4693a35b4aab5c77 (diff) | |
download | sqlite-c78c3c91ae722722b0f9ba59dd850885b5ffe5a4.tar.gz sqlite-c78c3c91ae722722b0f9ba59dd850885b5ffe5a4.zip |
Implement strict JSONB checking in the json_valid() function.
FossilOrigin-Name: 0f26d38880fcbc207abcc94dbc170a7428bab1b4f0b7731aaf5bee0224000994
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/json.c b/src/json.c index 067bdb473..ae6458cd5 100644 --- a/src/json.c +++ b/src/json.c @@ -3880,8 +3880,39 @@ static void jsonValidFunc( } case SQLITE_BLOB: { if( (flags & 0x0c)!=0 && jsonFuncArgMightBeBinary(argv[0]) ){ - /* TO-DO: strict checking if flags & 0x08 */ - res = 1; + if( flags & 0x04 ){ + /* Superficial checking only - accomplisehd by the + ** jsonFuncArgMightBeBinary() call above. */ + res = 1; + }else{ + /* Strict checking. Check by translating BLOB->TEXT->BLOB. If + ** no errors occur, call that a "strict check". */ + JsonParse px; + JsonString sx; + u8 oom = 0; + memset(&px, 0, sizeof(px)); + px.aBlob = (u8*)sqlite3_value_blob(argv[0]); + px.nBlob = sqlite3_value_bytes(argv[0]); + jsonStringInit(&sx, 0); + jsonXlateBlobToText(&px, 0, &sx); + jsonParseReset(&px); + if( sx.eErr & JSTRING_OOM ) oom = 1; + if( sx.eErr==0 ){ + memset(&px, 0, sizeof(px)); + px.zJson = sx.zBuf; + px.nJson = sx.nUsed; + if( jsonXlateTextToBlob(&px, 0)==px.nJson ){ + res = 1; + } + oom |= px.oom; + jsonParseReset(&px); + } + jsonStringReset(&sx); + if( oom ){ + sqlite3_result_error_nomem(ctx); + return; + } + } } break; } |