Improved robustness when translating corrupt JSONB into JSON text.

FossilOrigin-Name: 0caa320d9099adbaf98e3719003dbdc4d158abcb3d8a1af20fbcd4c08c970f4a
This commit is contained in:
drh 2023-10-10 18:42:08 +00:00
parent d88f378c7d
commit 59ded6b5f1
3 changed files with 24 additions and 12 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\spotential\sbuffer\soverrun\sdue\sto\scorrupt\sJSONB.
D 2023-10-10T18:32:14.227
C Improved\srobustness\swhen\stranslating\scorrupt\sJSONB\sinto\sJSON\stext.
D 2023-10-10T18:42:08.681
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -674,7 +674,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 e6e3641f54366634dc10dfb3684c3643821883b533f89c207b33dd2d23499c7d
F src/json.c fc5b17b021ce7699e08b8709698701d3de4128c07af53295ae1b241c38de7662
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@ -2129,8 +2129,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 c96eb7fb618dc0a5aeec8a5e85076475b77dcd56309438aba1f9bddfc8921e3c
R 24c9be5529f36a58a40f05b718ffa50e
P 5cbb861fc6cb7421a81c957ba9d576e0ae92cb4ed725cdb539b364d66f4ee145
R 56495ee1952f6b69fc5e0b7ca9cd10db
U drh
Z 1fee0a4053cb04fe5ff07cf374f7fcdd
Z 53d35a2e8ad88bb30ea85a59c02aea4e
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
5cbb861fc6cb7421a81c957ba9d576e0ae92cb4ed725cdb539b364d66f4ee145
0caa320d9099adbaf98e3719003dbdc4d158abcb3d8a1af20fbcd4c08c970f4a

View File

@ -3353,7 +3353,10 @@ static u32 jsonXlateBlobToText(
for(k=0; k<sz2 && zIn[k]!='\\'; k++){}
if( k>0 ){
jsonAppendRawNZ(pOut, zIn, k);
if( sz2<=k ) break;
if( sz2<=k ){
pOut->eErr |= JSTRING_MALFORMED;
break;
}
zIn += k;
sz2 -= k;
}
@ -3369,6 +3372,7 @@ static u32 jsonXlateBlobToText(
jsonAppendRawNZ(pOut, "\\u00", 4);
jsonAppendRawNZ(pOut, &zIn[2], 2);
if( sz2<2 ){
pOut->eErr |= JSTRING_MALFORMED;
sz2 = 0;
}else{
zIn += 2;
@ -3387,9 +3391,14 @@ static u32 jsonXlateBlobToText(
case '\n':
break;
case 0xe2:
assert( sz2>=4 );
assert( 0x80==(u8)zIn[2] );
assert( 0xa8==(u8)zIn[3] || 0xa9==(u8)zIn[3] );
if( sz2<4
|| 0x80!=(u8)zIn[2]
|| (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3])
){
pOut->eErr |= JSTRING_MALFORMED;
k = sz2;
break;
}
zIn += 2;
sz2 -= 2;
break;
@ -3397,7 +3406,10 @@ static u32 jsonXlateBlobToText(
jsonAppendRawNZ(pOut, zIn, 2);
break;
}
if( sz2<2 ) break;
if( sz2<2 ){
pOut->eErr |= JSTRING_MALFORMED;
break;
}
zIn += 2;
sz2 -= 2;
}