From 7d207bf4836753fb0b73aa2773b7958807d4e5ec Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 28 Jul 2023 01:19:44 +0000 Subject: [PATCH] Add an OOM check to the previous check-in. Minor internal API renaming. FossilOrigin-Name: 6b56e4d62b4945e52978d00aa8e2984faa731c92a7e002e81524fcfcf8ba0cce --- ext/jni/src/c/sqlite3-jni.c | 31 ++++++++++++++++++++----------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 907c6a9d23..fba90108d1 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -723,8 +723,10 @@ static void * getNativePointer(JNIEnv * env, jobject pObj, const char *zClassNam xStep() and xFinal() methods. isFinal must be 1 for xFinal() calls and 0 for all others. + + Returns 0 on succes, SQLITE_NOMEM on allocation error. */ -static void setAggregateContext(JNIEnv * env, jobject jCx, +static int s3jni_setAggregateContext(JNIEnv * env, jobject jCx, sqlite3_context * pCx, int isFinal){ jmethodID setter; @@ -745,8 +747,11 @@ static void setAggregateContext(JNIEnv * env, jobject jCx, } } pAgg = sqlite3_aggregate_context(pCx, isFinal ? 0 : 8); - (*env)->CallVoidMethod(env, jCx, setter, (jlong)pAgg); - IFTHREW_REPORT; + if( pAgg ){ + (*env)->CallVoidMethod(env, jCx, setter, (jlong)pAgg); + IFTHREW_REPORT; + } + return pAgg ? (int)0 : SQLITE_NOMEM; } @@ -1156,11 +1161,13 @@ static int udf_xFSI(sqlite3_context* pCx, int argc, if(rc) return rc; //MARKER(("UDF::%s.%s()\n", s->zFuncName, zFuncType)); if( UDF_SCALAR != s->type ){ - setAggregateContext(env, args.jcx, pCx, 0); + rc = s3jni_setAggregateContext(env, args.jcx, pCx, 0); } - (*env)->CallVoidMethod(env, s->jObj, xMethodID, args.jcx, args.jargv); - IFTHREW{ - rc = udf_report_exception(pCx,s, zFuncType); + if( 0 == rc ){ + (*env)->CallVoidMethod(env, s->jObj, xMethodID, args.jcx, args.jargv); + IFTHREW{ + rc = udf_report_exception(pCx,s, zFuncType); + } } UNREF_L(args.jcx); UNREF_L(args.jargv); @@ -1180,11 +1187,13 @@ static int udf_xFV(sqlite3_context* cx, UDFState * s, } //MARKER(("UDF::%s.%s()\n", s->zFuncName, zFuncType)); if( UDF_SCALAR != s->type ){ - setAggregateContext(env, jcx, cx, 1); + rc = s3jni_setAggregateContext(env, jcx, cx, 1); } - (*env)->CallVoidMethod(env, s->jObj, xMethodID, jcx); - IFTHREW{ - rc = udf_report_exception(cx,s, zFuncType); + if( 0 == rc ){ + (*env)->CallVoidMethod(env, s->jObj, xMethodID, jcx); + IFTHREW{ + rc = udf_report_exception(cx,s, zFuncType); + } } UNREF_L(jcx); return rc; diff --git a/manifest b/manifest index 7fe2d447fd..058fbe8d09 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\smaking\suse\sof\ssqlite3_aggregate_context()\s(in\sa\sroundabout\sway)\sfrom\sJava\sto\saccumulate\sstate\swithin\saggregate\sand\swindow\sUDFs. -D 2023-07-28T01:12:47.322 +C Add\san\sOOM\scheck\sto\sthe\sprevious\scheck-in.\sMinor\sinternal\sAPI\srenaming. +D 2023-07-28T01:19:44.606 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -232,7 +232,7 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/jni/GNUmakefile 56a014dbff9516774d895ec1ae9df0ed442765b556f79a0fc0b5bc438217200d F ext/jni/README.md 042762dbf047667783a5bd0aec303535140f302debfbd259c612edf856661623 -F ext/jni/src/c/sqlite3-jni.c 8d3ae5c0474548b1b95fea888227a4f617b9302a7e230bb5ff1b3735fe85fb03 +F ext/jni/src/c/sqlite3-jni.c 7e76652684c38df7c48ac3300056601202b0c45d91c5f3671725e17c3c69ec6a F ext/jni/src/c/sqlite3-jni.h c9bb150a38dce09cc2794d5aac8fa097288d9946fbb15250fd0a23c31957f506 F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1 @@ -2067,8 +2067,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 dc356667a8f4fa31a3fef1ae35873d834d27fd6a9f0818d6fb85e4751fde9fe5 -R 6f355aed3877133b3fb6aa6671123d94 +P 640574984741c7a9472d7f8be7bce87e736d7947ce673ae4a25008d74238ad90 +R ce71c2fd0629446f06e751d7b64d5f7d U stephan -Z 75e450fbcee41582218a9562a53136a5 +Z 3429cf1394e9a8e9214fcef9821d7359 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c7d6c30d99..b7049ce4d7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -640574984741c7a9472d7f8be7bce87e736d7947ce673ae4a25008d74238ad90 \ No newline at end of file +6b56e4d62b4945e52978d00aa8e2984faa731c92a7e002e81524fcfcf8ba0cce \ No newline at end of file