aboutsummaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authordrh <>2024-01-29 12:50:32 +0000
committerdrh <>2024-01-29 12:50:32 +0000
commit3fc7a34efc5b840c069a4d55f61f14b3d68df85b (patch)
tree7ae8ca6f35e66146a5b3e194a380b7ac0d5ce479 /src/json.c
parent4c11a5251a084d307ab11a458749408a5623fd9e (diff)
downloadsqlite-3fc7a34efc5b840c069a4d55f61f14b3d68df85b.tar.gz
sqlite-3fc7a34efc5b840c069a4d55f61f14b3d68df85b.zip
When rendering JSONB back into text JSON, report an error if a zero-length
integer or floating-point node is encountered. Otherwise, if the node occurs at the very end of the JSONB, the rendering logic might read one byte past the end of the initialized part of the BLOB byte array. OSSFuzz 66284. FossilOrigin-Name: b0eb279ea83c1c788c39fb90e178ec99fa4c782195c376a420c661fedf4545a7
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index c7412d3c7..d69d96793 100644
--- a/src/json.c
+++ b/src/json.c
@@ -2124,6 +2124,7 @@ static u32 jsonTranslateBlobToText(
}
case JSONB_INT:
case JSONB_FLOAT: {
+ if( sz==0 ) goto malformed_jsonb;
jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
break;
}
@@ -2132,6 +2133,7 @@ static u32 jsonTranslateBlobToText(
sqlite3_uint64 u = 0;
const char *zIn = (const char*)&pParse->aBlob[i+n];
int bOverflow = 0;
+ if( sz==0 ) goto malformed_jsonb;
if( zIn[0]=='-' ){
jsonAppendChar(pOut, '-');
k++;
@@ -2154,6 +2156,7 @@ static u32 jsonTranslateBlobToText(
case JSONB_FLOAT5: { /* Float literal missing digits beside "." */
u32 k = 0;
const char *zIn = (const char*)&pParse->aBlob[i+n];
+ if( sz==0 ) goto malformed_jsonb;
if( zIn[0]=='-' ){
jsonAppendChar(pOut, '-');
k++;
@@ -2291,6 +2294,7 @@ static u32 jsonTranslateBlobToText(
}
default: {
+ malformed_jsonb:
pOut->eErr |= JSTRING_MALFORMED;
break;
}