From: drh <> Date: Sat, 2 Dec 2023 21:39:34 +0000 (+0000) Subject: Implement strict JSONB checking in the json_valid() function. X-Git-Tag: version-3.45.0~116^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c78c3c91ae722722b0f9ba59dd850885b5ffe5a4;p=thirdparty%2Fsqlite.git Implement strict JSONB checking in the json_valid() function. FossilOrigin-Name: 0f26d38880fcbc207abcc94dbc170a7428bab1b4f0b7731aaf5bee0224000994 --- diff --git a/manifest b/manifest index cc84f09d52..95a05c007f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sreported\sby\sMSVC. -D 2023-12-02T20:37:45.416 +C Implement\sstrict\sJSONB\schecking\sin\sthe\sjson_valid()\sfunction. +D 2023-12-02T21:39:34.516 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -688,7 +688,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c fc67289aebe1ab7d3ccc31ec61b0fcea1d724f23026d072c05242dcc57049edf +F src/json.c fd321d1ab2d6f42354bd2ff7bc4974ab8dd9eee977e4e8e137cf1360873ef052 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9 @@ -2145,8 +2145,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c640754df0d3ffdad994745f0d0e10c8f19f424b87f6a6e6e269491a0350b950 -R cbbd74dd3f256fc8164ba32c868936ce +P 419652c0c82980bd043584dcd2976f91dfff7b926b216d597698299850b855c0 +R ed8c7ad5ad50d0c7dab9c9a4109db3da U drh -Z de70fb53fc1b64715f23def652af30f4 +Z 50662e1c3dbad4c9b4aaea32a805ad55 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 304fd5742b..c4f20a42ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -419652c0c82980bd043584dcd2976f91dfff7b926b216d597698299850b855c0 \ No newline at end of file +0f26d38880fcbc207abcc94dbc170a7428bab1b4f0b7731aaf5bee0224000994 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 067bdb4739..ae6458cd59 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; }