From: drh <> Date: Mon, 21 Apr 2025 20:58:49 +0000 (+0000) Subject: Further improvements to the decision of whether or not a BLOB input X-Git-Tag: major-release~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81cde80f7b0fec5bf64fb450e94a62047fb5c5fd;p=thirdparty%2Fsqlite.git Further improvements to the decision of whether or not a BLOB input is JSONB. FossilOrigin-Name: 6538813cb89f6109727481e29633e2e98f98e0257c58695e3b53e8ce237d9195 --- diff --git a/manifest b/manifest index 6f71143f32..949c0e4986 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\sa\sbetter\sjob\sof\sproviding\sbug\scompatibility\swith\sSQLite\s3.44.0.\s\sSee\n[forum:/forumpost/07e206fcd6|forum\sthread\s07e206fcd6]\sfor\sbackground. -D 2025-04-21T19:53:12.406 +C Further\simprovements\sto\sthe\sdecision\sof\swhether\sor\snot\sa\sBLOB\sinput\nis\sJSONB. +D 2025-04-21T20:58:49.823 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -746,7 +746,7 @@ F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c d05934dfab2c5c0c480fc6fd2038f11215661de08ea6ff38d2563216bd555c1b -F src/json.c d13d5e29d18b1b711d832cab48f48fab6705747abbac0ab65953c06eba74c99d +F src/json.c bb0f8f2fa2c0fb4cbcc3d8cc7abdaf161b341d541455069dda310645f031734c F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 07f78d917ffcdf327982840cfd8e855fd000527a2ea5ace372ce4febcbd0bf97 @@ -2216,8 +2216,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ea9acb5573f4d71a314e4467d30477a1d01c8db648985750a42b3c047f404c9c -R ead9acfd8b581f4510534b8b584f9293 +P 614d061b32c3bdf4825323d6f8e8a98624e4eeeb96dd442d8e365527122ed3bc +R 8a150a5cec72c6ab77984c7d65063b89 U drh -Z dd601f105d2c079fb81118dbb59f331e +Z 59b3d2a5c6021cf082dd8b7ce8b12041 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8beea29ca5..a056e0af7c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -614d061b32c3bdf4825323d6f8e8a98624e4eeeb96dd442d8e365527122ed3bc +6538813cb89f6109727481e29633e2e98f98e0257c58695e3b53e8ce237d9195 diff --git a/src/json.c b/src/json.c index 72b52efd7c..c29caa46bc 100644 --- a/src/json.c +++ b/src/json.c @@ -3489,7 +3489,7 @@ jsonInsertIntoBlob_patherror: ** ** The first byte of valid JSON text must be one of: '{', '[', '"', ' ', '\n', ** '\r', '\t', '-', or a digit '0' through '9'. Of these, only a subset -** can also be the first byte of JSONB: '{', '[', '\n', '\t', and digits '3' +** can also be the first byte of JSONB: '{', '[', and digits '3' ** through '9'. In every one of those cases, the payload size is 7 bytes ** or less. So if we do full JSONB validation for every BLOB where the ** payload is less than 7 bytes, we will never get a false positive for @@ -3497,16 +3497,19 @@ jsonInsertIntoBlob_patherror: */ static int jsonArgIsJsonb(sqlite3_value *pArg, JsonParse *p){ u32 n, sz = 0; + u8 c; if( sqlite3_value_type(pArg)!=SQLITE_BLOB ) return 0; p->aBlob = (u8*)sqlite3_value_blob(pArg); p->nBlob = (u32)sqlite3_value_bytes(pArg); if( p->nBlob>0 && ALWAYS(p->aBlob!=0) - && (p->aBlob[0] & 0x0f)<=JSONB_OBJECT + && ((c = p->aBlob[0]) & 0x0f)<=JSONB_OBJECT && (n = jsonbPayloadSize(p, 0, &sz))>0 && sz+n==p->nBlob - && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0) - && (sz>7 || (sz&1)==0 || jsonbValidityCheck(p, 0, p->nBlob, 1)==0) + && ((c & 0x0f)>JSONB_FALSE || sz==0) + && (sz>7 + || (c!=0x7b && c!=0x5b && !sqlite3Isdigit(c)) + || jsonbValidityCheck(p, 0, p->nBlob, 1)==0) ){ return 1; } @@ -4602,7 +4605,7 @@ static void jsonValidFunc( JsonParse py; memset(&py, 0, sizeof(py)); if( jsonArgIsJsonb(argv[0], &py) ){ - if( (flags & 0x04)!=0 || py.nBlob<=7 ){ + if( flags & 0x04 ){ /* Superficial checking only - accomplished by the ** jsonArgIsJsonb() call above. */ res = 1;