From: drh <> Date: Tue, 24 Mar 2026 11:54:55 +0000 (+0000) Subject: Improved error messages for JSONB nested too deep. X-Git-Tag: major-release~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=814f592cf0b22225139ade956e3c9a6e1434554e;p=thirdparty%2Fsqlite.git Improved error messages for JSONB nested too deep. FossilOrigin-Name: 82036fafa175e798fd32b3dc4ad043fc2bbe2bb2af17781f12dcb4d23a233865 --- diff --git a/manifest b/manifest index 200edb50ba..c240c1a97d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sstale\sreference\sto\sthe\slong-removed\sSQLITE_MUTEX_APPDEF,\sas\spointed\sout\sin\s[forum:348453389b|forum\spost\s348453389b]. -D 2026-03-24T11:33:22.229 +C Improved\serror\smessages\sfor\sJSONB\snested\stoo\sdeep. +D 2026-03-24T11:54:55.461 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -694,7 +694,7 @@ F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf F src/hwtime.h 21c2cf1f736e7b97502c3674d0c386db3f06870d6f10d0cf8174e2a4b8cb726e F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c dfd311b0ac2d4f6359e62013db67799757f4d2cc56cca5c10f4888acfbbfa3fd -F src/json.c b2e4b71740825ae92170b7abf8b30e42eca64ade30eb34fbdd27d8598b2248ad +F src/json.c 465a8b7c41f42a5c64036adf4619b34d7fb3ad0947c0662c1c5c372b41649475 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 187929338d21f43cbdea359a3c1ec61294f39b7f9032e824c1dbb79f9994c838 F src/main.c 31a13302193fbd51279c7e69cdfa0320d0de7629f9151e0964c1d320e8bdd7a4 @@ -2195,8 +2195,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 1cd30c4827e382861cf12af48579eedc9685b9612dedb6a2844f20355b910e7e -R 8780cbb3021d5a878a547468e242a47c -U stephan -Z 08035a5f34f6050f5dbf728c38a452eb +P cb8e55b59113d0102c50db0a43b1b59d531cdcb12a7cce4c4c9a428c7c6e1adf +R 8b2a817ae31399c7deb32904feb440aa +U drh +Z 77bd223cb339720304c49139be84aed5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e71d448193..5b59c597c4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb8e55b59113d0102c50db0a43b1b59d531cdcb12a7cce4c4c9a428c7c6e1adf +82036fafa175e798fd32b3dc4ad043fc2bbe2bb2af17781f12dcb4d23a233865 diff --git a/src/json.c b/src/json.c index 01aa274a31..da514afd5a 100644 --- a/src/json.c +++ b/src/json.c @@ -313,7 +313,8 @@ struct JsonString { /* Allowed values for JsonString.eErr */ #define JSTRING_OOM 0x01 /* Out of memory */ #define JSTRING_MALFORMED 0x02 /* Malformed JSONB */ -#define JSTRING_ERR 0x04 /* Error already sent to sqlite3_result */ +#define JSTRING_TOODEEP 0x04 /* JSON nested too deep */ +#define JSTRING_ERR 0x08 /* Error already sent to sqlite3_result */ /* The "subtype" set for text JSON values passed through using ** sqlite3_result_subtype() and sqlite3_value_subtype(). @@ -561,6 +562,15 @@ static void jsonStringOom(JsonString *p){ jsonStringReset(p); } +/* Report JSON nested too deep +*/ +static void jsonStringTooDeep(JsonString *p){ + p->eErr |= JSTRING_TOODEEP; + assert( p->pCtx!=0 ); + sqlite3_result_error(p->pCtx, "JSON nested too deep", -1); + jsonStringReset(p); +} + /* Enlarge pJson->zBuf so that it can hold at least N more bytes. ** Return zero on success. Return non-zero on an OOM error */ @@ -877,6 +887,8 @@ static void jsonReturnString( } }else if( p->eErr & JSTRING_OOM ){ sqlite3_result_error_nomem(p->pCtx); + }else if( p->eErr & JSTRING_TOODEEP ){ + /* error already in p->pCtx */ }else if( p->eErr & JSTRING_MALFORMED ){ sqlite3_result_error(p->pCtx, "malformed JSON", -1); } @@ -2361,7 +2373,7 @@ static u32 jsonTranslateBlobToText( j = i+n; iEnd = j+sz; if( ++pParse->iDepth > JSON_MAX_DEPTH ){ - jsonStringOom(pOut); + jsonStringTooDeep(pOut); } while( jeErr==0 ){ j = jsonTranslateBlobToText(pParse, j, pOut); @@ -2379,7 +2391,7 @@ static u32 jsonTranslateBlobToText( j = i+n; iEnd = j+sz; if( ++pParse->iDepth > JSON_MAX_DEPTH ){ - jsonStringOom(pOut); + jsonStringTooDeep(pOut); } while( jeErr==0 ){ j = jsonTranslateBlobToText(pParse, j, pOut); @@ -2458,7 +2470,7 @@ static u32 jsonTranslateBlobToPrettyText( jsonAppendChar(pOut, '\n'); pPretty->nIndent++; if( pPretty->nIndent >= JSON_MAX_DEPTH ){ - jsonStringOom(pOut); + jsonStringTooDeep(pOut); } while( pOut->eErr==0 ){ jsonPrettyIndent(pPretty); @@ -2482,7 +2494,7 @@ static u32 jsonTranslateBlobToPrettyText( jsonAppendChar(pOut, '\n'); pPretty->nIndent++; if( pPretty->nIndent >= JSON_MAX_DEPTH ){ - jsonStringOom(pOut); + jsonStringTooDeep(pOut); } pParse->iDepth = pPretty->nIndent; while( pOut->eErr==0 ){