diff --git a/manifest b/manifest index db03cd3807..c0fde4f425 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sthe\sinternal\sroutine\sjsonMergePatchBlob()\sto\sjust\sjsonMergePatch(). -D 2023-12-04T23:12:57.639 +C Fix\sOOM\sand\scorrupt\sJSONB\shandling\sin\sjson_patch(). +D 2023-12-05T00:17:17.234 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 d2385c49df219c1d10cb0a3a817df5aa7bd2ef86772f24f3763e2341b0875b70 +F src/json.c 4dadaf584446be580a7a0054d25c4fc3ae17065952d5d1ffdb7a05a1cc102519 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 aa85df2d26b74c171c55bde19ef17c4f11f40b8af7181bbf7162f87cdea7e88b -R 6429070b5e7eb1a8581d28813921879f +P ebf667b616235bb64b83832008342ba5e7b10b2c170d7cebc431f040fef7ecfb +R 63dbe3f87f86d8011f70d9756cf66af6 U drh -Z f2f7e0af6ffb5ce2a2c95b6ed2412ab3 +Z f62ad889060f6abf937d9ec41a83acdd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7301a291e0..5223dccf73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ebf667b616235bb64b83832008342ba5e7b10b2c170d7cebc431f040fef7ecfb \ No newline at end of file +1910feb0b7d5cc2b810c3322f6cca281d8730182d30d162bd7bb56800979ea91 \ No newline at end of file diff --git a/src/json.c b/src/json.c index e0651130ff..57082cf3f8 100644 --- a/src/json.c +++ b/src/json.c @@ -3348,11 +3348,11 @@ static int jsonMergePatch( pTarget->aBlob[iTarget] = (x & 0xf0) | JSONB_OBJECT; } n = jsonbPayloadSize(pPatch, iPatch, &sz); - if( n==0 ) return JSON_MERGE_BADPATCH; + if( NEVER(n==0) ) return JSON_MERGE_BADPATCH; iPCursor = iPatch+n; iPEnd = iPCursor+sz; n = jsonbPayloadSize(pTarget, iTarget, &sz); - if( n==0 ) return JSON_MERGE_BADTARGET; + if( NEVER(n==0) ) return JSON_MERGE_BADTARGET; iTStart = iTarget+n; iTEndBE = iTStart+sz; @@ -3365,7 +3365,7 @@ static int jsonMergePatch( nPLabel = jsonbPayloadSize(pPatch, iPCursor, &szPLabel); if( nPLabel==0 ) return JSON_MERGE_BADPATCH; iPValue = iPCursor + nPLabel + szPLabel; - if( iPCursor>=iPEnd ) return JSON_MERGE_BADPATCH; + if( iPValue>=iPEnd ) return JSON_MERGE_BADPATCH; nPValue = jsonbPayloadSize(pPatch, iPValue, &szPValue); if( nPValue==0 ) return JSON_MERGE_BADPATCH; iPCursor = iPValue + nPValue + szPValue; @@ -3397,13 +3397,12 @@ static int jsonMergePatch( }else{ /* Should rarely happen */ JsonString s1, s2; - int isEqual; + int isEqual, isOom; jsonStringInit(&s1, 0); jsonXlateBlobToText(pTarget, iTLabel, &s1); - if( s1.eErr ) return JSON_MERGE_OOM; jsonStringInit(&s2, 0); jsonXlateBlobToText(pPatch, iPLabel, &s2); - if( s2.eErr ) return JSON_MERGE_OOM; + isOom = s1.eErr || s2.eErr; if( s1.nUsed==s2.nUsed && memcmp(s1.zBuf, s2.zBuf, s1.nUsed)==0 ){ isEqual = 1; }else{ @@ -3411,6 +3410,7 @@ static int jsonMergePatch( } jsonStringReset(&s1); jsonStringReset(&s2); + if( isOom ) return JSON_MERGE_OOM; if( isEqual ) break; } iTCursor = iTValue + nTValue + szTValue; @@ -3420,9 +3420,9 @@ static int jsonMergePatch( /* A match was found. Algorithm line 08 */ if( x==0 ){ /* Patch value is NULL. Algorithm line 09 */ - jsonBlobEdit(pTarget, iTLabel, nTLabel+szTLabel+nTValue+szTValue, - 0, 0); - if( pTarget->oom ) return JSON_MERGE_OOM; + jsonBlobEdit(pTarget, iTLabel, nTLabel+szTLabel+nTValue+szTValue, 0,0); + /* vvvvvv----- No OOM on a delete-only edit */ + if( NEVER(pTarget->oom) ) return JSON_MERGE_OOM; }else{ /* Algorithm line 12 */ int rc, savedDelta = pTarget->delta;