]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In the decimal.c extension, set a default MAX_DIGITS to 100 million.
authordrh <>
Sun, 8 Mar 2026 18:50:35 +0000 (18:50 +0000)
committerdrh <>
Sun, 8 Mar 2026 18:50:35 +0000 (18:50 +0000)
Do not allow integer overflow of the N parameter to the internal
decimal_round() function.

FossilOrigin-Name: d0e23423d1bdd0482db4b74ef0fde2fbc2bbad02a7b92ba45a27ca57f4740e16

ext/misc/decimal.c
manifest
manifest.uuid

index 541ef337685e36ddc61f1c076f3497601eb54cc9..7faa14747e96e31b921af987a110cac722289d9e 100644 (file)
@@ -31,6 +31,10 @@ SQLITE_EXTENSION_INIT1
 #define IsSpace(X)  isspace((unsigned char)X)
 #endif
 
+#ifndef SQLITE_DECIMAL_MAX_DIGIT
+# define SQLITE_DECIMAL_MAX_DIGIT 10000000
+#endif
+
 /* A decimal object */
 typedef struct Decimal Decimal;
 struct Decimal {
@@ -164,9 +168,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
     for(i=0; i<p->nDigit && p->a[i]==0; i++){}
     if( i>=p->nDigit ) p->sign = 0;
   }
-#if SQLITE_DECIMAL_MAX_DIGIT+0>10
   if( p->nDigit>SQLITE_DECIMAL_MAX_DIGIT ) goto new_from_text_failed;
-#endif
   return p;
 
 new_from_text_failed:
@@ -305,6 +307,7 @@ static void decimal_round(Decimal *p, int N){
   int nZero;
   if( N<1 ) return;
   if( p==0 ) return;
+  if( p->nDigit<=N ) return;
   for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){}
   N += nZero;
   if( p->nDigit<=N ) return;
@@ -467,9 +470,7 @@ static void decimal_expand(Decimal *p, int nDigit, int nFrac){
   nAddFrac = nFrac - p->nFrac;
   nAddSig = (nDigit - p->nDigit) - nAddFrac;
   if( nAddFrac==0 && nAddSig==0 ) return;
-#if SQLITE_DECIMAL_MAX_DIGIT+0>10
   if( nDigit+1>SQLITE_DECIMAL_MAX_DIGIT ){ p->oom = 1; return; }
-#endif
   a = sqlite3_realloc64(p->a, nDigit+1);
   if( a==0 ){
     p->oom = 1;
@@ -580,9 +581,7 @@ static void decimalMul(Decimal *pA, Decimal *pB){
   sumDigit = pA->nDigit;
   sumDigit += pB->nDigit;
   sumDigit += 2;
-#if SQLITE_DECIMAL_MAX_DIGIT+0>10
   if( sumDigit>SQLITE_DECIMAL_MAX_DIGIT ){ pA->oom = 1; return; }
-#endif
   acc = sqlite3_malloc64( sumDigit );
   if( acc==0 ){
     pA->oom = 1;
index 896603afae09e5edbeb8cf5f855a1e15fdaa8cab..219dbd8253550e6cc28f3f255307406386e03de8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Consolidate\sthe\sopfs\sand\sopfs-wl\stester1\stests\susing\sthe\spreprocessor.
-D 2026-03-08T17:07:01.581
+C In\sthe\sdecimal.c\sextension,\sset\sa\sdefault\sMAX_DIGITS\sto\s100\smillion.\nDo\snot\sallow\sinteger\soverflow\sof\sthe\sN\sparameter\sto\sthe\sinternal\ndecimal_round()\sfunction.
+D 2026-03-08T18:50:35.538
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -370,7 +370,7 @@ F ext/misc/completion.c 99589a9f04113e9a169312d132730131963451a30abd6704d7808623
 F ext/misc/compress.c 8191118b9b73e7796c961790db62d35d9b0fb724b045e005a5713dc9e0795565
 F ext/misc/csv.c e82124eabee0e692d7b90ab8b2c34fadbf7b375279f102567fa06e4da4b771bf
 F ext/misc/dbdump.c 678f1b9ae2317b4473f65d03132a2482c3f4b08920799ed80feedd2941a06680
-F ext/misc/decimal.c 0b6273955de8fd42fa54723e4976a8306965dd398e7134a8d9d65787d07d87a9
+F ext/misc/decimal.c b64911bcc77ed86e40075a6a51a9efb48520720f289b9be544adf6e2587094d5
 F ext/misc/eval.c 04bc9aada78c888394204b4ed996ab834b99726fb59603b0ee3ed6e049755dc1
 F ext/misc/explain.c 606100185fb90d6a1eade1ed0414d53503c86820d8956a06e3b0a56291894f2b
 F ext/misc/fileio.c 33165b3cd99f83dcd333a338eb51491f6b01c8d96cb6ae81f96a6a096834e030
@@ -2192,8 +2192,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P 2e2339bd9e4293bad04ece7673a3048b99c2143cf9573ade2ec082d95744b981
-R 9cd4639cecfa2ed218f49daad5bfc92b
-U stephan
-Z 873b4faa43addc72711cdf46682db1a4
+P 77846c8c7aa4625729a5e113c12e7d16efc88c1306c01ba36f47240aac450b0f
+R a756ed3fd63cf7cc47a1e12edb8d7d54
+U drh
+Z d8105cfe6e2ec1bd1dccf656d79dfdcd
 # Remove this line to create a well-formed Fossil manifest.
index acec13aaa631a797a05e580e557d19f5156a5c3e..931d97373496a5e9bea5124075ef0d89c2616323 100644 (file)
@@ -1 +1 @@
-77846c8c7aa4625729a5e113c12e7d16efc88c1306c01ba36f47240aac450b0f
+d0e23423d1bdd0482db4b74ef0fde2fbc2bbad02a7b92ba45a27ca57f4740e16