|
|
a87669 |
Subject: [PATCH] Limit the "precision" of floating-point to text conversions
|
|
|
a87669 |
in the printf() function to 100,000,000.
|
|
|
a87669 |
|
|
|
a87669 |
---
|
|
|
a87669 |
src/printf.c | 12 ++++++++++++
|
|
|
a87669 |
test/printf.test | 16 +++++++++++++---
|
|
|
a87669 |
2 files changed, 25 insertions(+), 3 deletions(-)
|
|
|
a87669 |
|
|
|
a87669 |
diff --git a/src/printf.c b/src/printf.c
|
|
|
a87669 |
index 7bce83f..260bf79 100644
|
|
|
a87669 |
--- a/src/printf.c
|
|
|
a87669 |
+++ b/src/printf.c
|
|
|
a87669 |
@@ -165,6 +165,13 @@ static char *getTextArg(PrintfArguments *p){
|
|
|
a87669 |
#endif
|
|
|
a87669 |
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
|
|
|
a87669 |
|
|
|
a87669 |
+/*
|
|
|
a87669 |
+** Hard limit on the precision of floating-point conversions.
|
|
|
a87669 |
+*/
|
|
|
a87669 |
+#ifndef SQLITE_PRINTF_PRECISION_LIMIT
|
|
|
a87669 |
+# define SQLITE_FP_PRECISION_LIMIT 100000000
|
|
|
a87669 |
+#endif
|
|
|
a87669 |
+
|
|
|
a87669 |
/*
|
|
|
a87669 |
** Render a string given by "fmt" into the StrAccum object.
|
|
|
a87669 |
*/
|
|
|
a87669 |
@@ -471,6 +478,11 @@ void sqlite3_str_vappendf(
|
|
|
a87669 |
length = 0;
|
|
|
a87669 |
#else
|
|
|
a87669 |
if( precision<0 ) precision = 6; /* Set default precision */
|
|
|
a87669 |
+#ifdef SQLITE_FP_PRECISION_LIMIT
|
|
|
a87669 |
+ if( precision>SQLITE_FP_PRECISION_LIMIT ){
|
|
|
a87669 |
+ precision = SQLITE_FP_PRECISION_LIMIT;
|
|
|
a87669 |
+ }
|
|
|
a87669 |
+#endif
|
|
|
a87669 |
if( realvalue<0.0 ){
|
|
|
a87669 |
realvalue = -realvalue;
|
|
|
a87669 |
prefix = '-';
|
|
|
a87669 |
diff --git a/test/printf.test b/test/printf.test
|
|
|
a87669 |
index d768898..a2b5e2a 100644
|
|
|
a87669 |
--- a/test/printf.test
|
|
|
a87669 |
+++ b/test/printf.test
|
|
|
a87669 |
@@ -538,9 +538,11 @@ do_test printf-2.1.2.8 {
|
|
|
a87669 |
do_test printf-2.1.2.9 {
|
|
|
a87669 |
sqlite3_mprintf_double {abc: %d %d (%1.1g) :xyz} 1 1 1.0e-20
|
|
|
a87669 |
} {abc: 1 1 (1e-20) :xyz}
|
|
|
a87669 |
-do_test printf-2.1.2.10 {
|
|
|
a87669 |
- sqlite3_mprintf_double {abc: %*.*f} 2000000000 1000000000 1.0e-20
|
|
|
a87669 |
-} {abc: }
|
|
|
a87669 |
+if {$SQLITE_MAX_LENGTH<=[expr 1000*1000*1000]} {
|
|
|
a87669 |
+ do_test printf-2.1.2.10 {
|
|
|
a87669 |
+ sqlite3_mprintf_double {abc: %*.*f} 2000000000 1000000000 1.0e-20
|
|
|
a87669 |
+ } {}
|
|
|
a87669 |
+}
|
|
|
a87669 |
do_test printf-2.1.3.1 {
|
|
|
a87669 |
sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 1.0
|
|
|
a87669 |
} {abc: (1.0) :xyz}
|
|
|
a87669 |
@@ -3777,4 +3779,12 @@ foreach ::iRepeat {0 1} {
|
|
|
a87669 |
}
|
|
|
a87669 |
}
|
|
|
a87669 |
|
|
|
a87669 |
+# 2020-05-23
|
|
|
a87669 |
+# ticket 23439ea582241138
|
|
|
a87669 |
+#
|
|
|
a87669 |
+do_execsql_test printf-16.1 {
|
|
|
a87669 |
+ SELECT printf('%.*g',2147483647,0.01);
|
|
|
a87669 |
+} {0.01}
|
|
|
a87669 |
+
|
|
|
a87669 |
+
|
|
|
a87669 |
finish_test
|
|
|
a87669 |
--
|
|
|
a87669 |
2.24.1
|
|
|
a87669 |
|