From: drh <> Date: Tue, 12 Dec 2023 02:31:12 +0000 (+0000) Subject: Validity checking of text nodes in JSONB. X-Git-Tag: version-3.45.0~94^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc1a39fd247cf90af0ae59304206faf7ecb61819;p=thirdparty%2Fsqlite.git Validity checking of text nodes in JSONB. FossilOrigin-Name: fa5160687c2f970d407e8af73c246f7cd806bb4ce35f29a79ac534a8646a6c8e --- diff --git a/manifest b/manifest index ada03e02f1..91ba64c3dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sjson_error_position()\sfunction\snow\sreports\san\sapproximate\sbyte\soffset\nto\sthe\sproblem\sin\sa\sJSONB\sif\sthere\sis\sa\sproblem. -D 2023-12-11T21:00:55.202 +C Validity\schecking\sof\stext\snodes\sin\sJSONB. +D 2023-12-12T02:31:12.655 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -696,7 +696,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 387dd9d7d63bac1e0068d66e8b40d86e1e2f0edc6930da28c67584c7a5a32872 +F src/json.c 34f829db190ae485926855da651d349eedb35fa56010266e14c0b094f536c9f5 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c ce714ee501122c76eb2e69b292bebe443aba611fc3b88e6786eb910285515fe4 @@ -2153,8 +2153,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 c3d60cf7028a333b825d5b89516945a73e0c158ac81d8bcc117d21bfd98602c8 -R eef20549bb0818034c7a80cb1490f371 +P 80d5d94dff6a2d2557039be3d7d47c1a6003c4b98defe0bd411acfeb963ad5dd +R 8ac47232b4f02631d44b831db0790bc1 U drh -Z 99dd825f602cc4286df6f3fcbe1570d6 +Z 8178cefe916c4486a65df71a751de097 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 07345f0192..208d3cd26d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -80d5d94dff6a2d2557039be3d7d47c1a6003c4b98defe0bd411acfeb963ad5dd \ No newline at end of file +fa5160687c2f970d407e8af73c246f7cd806bb4ce35f29a79ac534a8646a6c8e \ No newline at end of file diff --git a/src/json.c b/src/json.c index 31367fe544..17ebc769cc 100644 --- a/src/json.c +++ b/src/json.c @@ -176,7 +176,9 @@ static const char jsonSpaces[] = "\011\012\015\040"; /* ** Characters that are special to JSON. Control characters, -** '"' and '\\'. +** '"' and '\\' and '\''. Actually, '\'' is not special to +** canonical JSON, but it is special in JSON-5, so we include +** it in the set of special characters. */ static const char jsonIsOk[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -337,6 +339,7 @@ static void jsonReturnParse(sqlite3_context*,JsonParse*); static JsonParse *jsonParseFuncArg(sqlite3_context*,sqlite3_value*,u32); static void jsonParseFree(JsonParse*); static u32 jsonbPayloadSize(const JsonParse*, u32, u32*); +static u32 jsonUnescapeOneChar(const char*, u32, u32*); /************************************************************************** ** Utility routines for dealing with JsonCache objects @@ -1346,10 +1349,42 @@ static u32 jsonbValidityCheck( return 0; } case JSONB_TEXT: { + j = i+n; + k = j+sz; + while( j=k ){ + return j+1; + }else if( strchr("\"\\/bfnrt",z[j+1])!=0 ){ + j++; + }else if( z[j+1]=='u' ){ + if( j+5>=k ) return j+1; + if( !jsonIs4Hex((const char*)&z[j+2]) ) return j+1; + j++; + }else if( x!=JSONB_TEXT5 ){ + return j+1; + }else{ + u32 c = 0; + u32 szC = jsonUnescapeOneChar((const char*)&z[j], k-j, &c); + if( c==0xfffd ) return j+1; + j += szC - 1; + } + } + j++; + } return 0; } case JSONB_TEXTRAW: { @@ -1625,6 +1660,8 @@ json_parse_restart: /* Control characters are not allowed in strings */ pParse->iErr = j; return -1; + }else if( c=='"' ){ + opcode = JSONB_TEXT5; } j++; } @@ -2084,13 +2121,13 @@ static u32 jsonXlateBlobToText( } break; } + case JSONB_TEXT: case JSONB_TEXTJ: { jsonAppendChar(pOut, '"'); jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz); jsonAppendChar(pOut, '"'); break; } - case JSONB_TEXT: case JSONB_TEXT5: { const char *zIn; u32 k;