From: drh <> Date: Wed, 30 Aug 2023 18:27:46 +0000 (+0000) Subject: Fix a bug in json_array_length() introduced in version 3.43.0 X-Git-Tag: version-3.43.1~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5baa631ceae1562c871082435a8ff5ee9f97c0f7;p=thirdparty%2Fsqlite.git Fix a bug in json_array_length() introduced in version 3.43.0 If the JSON input comes from json_remove(), the removed array entries are still counted as part of the array length. FossilOrigin-Name: db7cb6cb73e606667f0ac52a2e84be6e755ae2792fc64e494ed08d0d3fab2863 --- diff --git a/manifest b/manifest index 8841ba64b7..2c71e4874a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sAVG()\sand\sTOTAL()\sfunctions\sso\sthat\sthey\swork\swith\sinfinitites. -D 2023-08-30T16:08:30.623 +C Fix\sa\sbug\sin\sjson_array_length()\sintroduced\sin\sversion\s3.43.0\nIf\sthe\sJSON\sinput\scomes\sfrom\sjson_remove(),\nthe\sremoved\sarray\sentries\sare\sstill\scounted\sas\spart\sof\sthe\sarray\slength. +D 2023-08-30T18:27:46.945 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -644,7 +644,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 ae840f87b418f039f5d336b488933d09396bd31e6b31e855b93055ccaee4e255 +F src/json.c 51141f1c09ccb177057e5813e6302a5e32e5ba88cc4a756318a35081010fc6df F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c fde8f13c876a658b4e8b74b77d875ca887915c174ea6a2f3122d80966f93d865 @@ -1274,7 +1274,7 @@ F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd286 F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307 F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x F test/json101.test dc9d5a2a5b1fd1b54dbd71c538b17933cc98d84b4c1f821ead754933663dca55 -F test/json102.test 24f6f204f9cde45b971016691d0b92a9b4c58040d699e36d6b12cb165f9083ff +F test/json102.test 4c69694773a470f1fda34e5f4ba24920b35184fb66050b450fc2ef9ab5ad310b F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d @@ -2092,9 +2092,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 692266abd107920ef8bec16c5e2c6226746948140dd8da17cdf2132fee4338f6 -Q +6df6f17ccb404c648076ccff4200d0eb5437f0e3e82424bf3da5ea682b107bb4 -R 91c512eb5ecf2b495e648d6381e248bf +P 97e20716c7c5c9c96a693835f99692d4cea088edebb9e422057bcb59829b798f +Q +69a635958a4a14187e88dd297df8978a4805b1b0c7bff3ec29d5632c0f68d889 +R 8418b86ba3026abdf6cefa97401d3d7d U drh -Z c3c82b30f339c4d0d44d7d774602974f +Z 979ae0a0217d20fc319c83942229e1ed # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ebf372b137..42f6601df2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -97e20716c7c5c9c96a693835f99692d4cea088edebb9e422057bcb59829b798f \ No newline at end of file +db7cb6cb73e606667f0ac52a2e84be6e755ae2792fc64e494ed08d0d3fab2863 \ No newline at end of file diff --git a/src/json.c b/src/json.c index f8d4aa2a77..253fce9f49 100644 --- a/src/json.c +++ b/src/json.c @@ -2484,7 +2484,9 @@ static void jsonArrayLengthFunc( } if( pNode->eType==JSON_ARRAY ){ while( 1 /*exit-by-break*/ ){ - for(i=1; i<=pNode->n; n++){ + i = 1; + while( i<=pNode->n ){ + if( (pNode[i].jnFlags & JNODE_REMOVE)==0 ) n++; i += jsonNodeSize(&pNode[i]); } if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; diff --git a/test/json102.test b/test/json102.test index 276c1816a7..ce901efeb1 100644 --- a/test/json102.test +++ b/test/json102.test @@ -48,6 +48,9 @@ do_execsql_test json102-180 { do_execsql_test json102-190 { SELECT json_array_length('[1,2,3,4]'); } {{4}} +do_execsql_test json102-191 { + SELECT json_array_length( json_remove('[1,2,3,4]','$[2]') ); +} {{3}} do_execsql_test json102-200 { SELECT json_array_length('[1,2,3,4]', '$'); } {{4}}