]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix boundary cases of rowid lookup using very large floating point values -
authordrh <>
Sun, 19 Jul 2026 19:49:24 +0000 (19:49 +0000)
committerdrh <>
Sun, 19 Jul 2026 19:49:24 +0000 (19:49 +0000)
values near the minimum and maximum 64-bit signed integer.
[forum:/info/2026-07-19T07:31:46Z|Forum 2026-07-19T07:31:46Z].

FossilOrigin-Name: 987ba5a3dc5f2a2294b77ef3ec1ea06682f0530a7268777c6b64985dd0e90d40

manifest
manifest.uuid
src/vdbe.c
test/intpkey.test

index 0c8f7c60c63b2d5a1aa355019c0d5ea63d253ab0..0bbf74071adf78b8298dedfb0271ffb2e6596bbc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Latest\supstream\sjimsh0.c\sfor\sminor\sportability\simprovements\sand\scleanups.
-D 2026-07-19T12:56:34.893
+C Fix\sboundary\scases\sof\srowid\slookup\susing\svery\slarge\sfloating\spoint\svalues\s-\nvalues\snear\sthe\sminimum\sand\smaximum\s64-bit\ssigned\sinteger.\n[forum:/info/2026-07-19T07:31:46Z|Forum\s2026-07-19T07:31:46Z].
+D 2026-07-19T19:49:24.674
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -809,7 +809,7 @@ F src/upsert.c dd9f0fcccbfb4f20e1026a21a7254ba3f2c08e9cfa92affaff5b5ec3b00ea549
 F src/utf.c 7267c3fb9e2467020507601af3354c2446c61f444387e094c779dccd5ca62165
 F src/util.c fcab5d997364c657e973e2bd3b9d2181aeb0926be0c028f20dfd4445894af3b4
 F src/vacuum.c d3d35d8ae893d419ade5fa196d761a83bddcbb62137a1a157ae751ef38b26e82
-F src/vdbe.c 6397694fa506aa1841dc8bb6a17c514aa602a4ad2515024fcd5880558c1ef57f
+F src/vdbe.c 30a41b3b7452eba63ad6451d74b8363096b82eecb27c4c9ab1cb9c2aa6cf4ffb
 F src/vdbe.h 70e862ac8a11b590f8c1eaac17a0078429d42bc4ea3f757a9af0f451dd966a71
 F src/vdbeInt.h c31ba4dc8d280c2b1dc89c6fcee68f2555e3813ab34279552c20b964c0e338b1
 F src/vdbeapi.c 6ad0c841b6cb87de068f71787f385149d794e8830176bf72d09a36b9f655ac5b
@@ -1331,7 +1331,7 @@ F test/intarray.test bb976b0b3df0ebb6a2eddfb61768280440e672beba5460ed49679ea984c
 F test/intck01.sql cc67c49bb0dbffd8ede29d3e095ba2b758eaa3907eeeca3fd44048a01c4071d3
 F test/interrupt.test ac1ef50ec9ab8e4f0e17c47629f82539d4b22558904e321ed5abea2e6187da7a
 F test/interrupt2.test 7eaa40a975d950826cd56e6c37f0f0629adfa2d1a8d3333aff0ff7cf86069963
-F test/intpkey.test 7d54711acf553cdd641a40e9c6cfc2bf1a76070074940c1b126442517054320f
+F test/intpkey.test e8feb8326089e78bfb6bfe03c2005c920b87417a692f33369ae953692c51c8d9
 F test/intreal.test 68829a8bb073ee1610ca3f8f9e0f99b0371fb36e0fa64862dd5ced4ef03c2343
 F test/io.test d267fdc8915444a45e19841489033ebe70bb69f6db605b00df70be16b2a80f59
 F test/ioerr.test 78552a95d53b9674d85f63bdf3d76a8df70b4d5dba5a6a1b8a1d60f166cd2c6b
@@ -2215,8 +2215,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P bb65c3adcd79581715f90d287807a3f03b375f69957c7d0202d31b23cf627da0
-R 07d5ed11feeeb19c0c15c9e258798cf2
-U stephan
-Z c0d6fb70c2f55c80d47dcabd81ae5f01
+P 436cf63e941b3db936a01d4584c9e3cc9675ce9ef4b6689530218c27252c170d
+R d5f2585f74441642eac52f7b29db0d93
+U drh
+Z 7d9a924e268268fab71b80580c8683dc
 # Remove this line to create a well-formed Fossil manifest.
index 3aad1009494eb9c7efb7b9ab5557e2422e23a72d..5e80288db0138c645f9cd38cb7ef52d3f3ba7d1d 100644 (file)
@@ -1 +1 @@
-436cf63e941b3db936a01d4584c9e3cc9675ce9ef4b6689530218c27252c170d
+987ba5a3dc5f2a2294b77ef3ec1ea06682f0530a7268777c6b64985dd0e90d40
index b2fabcd7580095acee84e40c3134035e74a8f021..e6a01e72767db60e17ac33eac009e89dbd34b405 100644 (file)
@@ -5531,7 +5531,7 @@ case OP_SeekRowid: {        /* jump0, in3, ncycle */
   VdbeCursor *pC;
   BtCursor *pCrsr;
   int res;
-  u64 iKey;
+  i64 iKey;
 
   pIn3 = &aMem[pOp->p3];
   testcase( pIn3->flags & MEM_Int );
@@ -5545,9 +5545,19 @@ case OP_SeekRowid: {        /* jump0, in3, ncycle */
     ** changing the datatype of pIn3, however, as it is used by other
     ** parts of the prepared statement. */
     Mem x = pIn3[0];
-    applyAffinity(&x, SQLITE_AFF_NUMERIC, encoding);
-    if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
-    iKey = x.u.i;
+    if( x.flags & MEM_Str ){
+      applyNumericAffinity(&x, 1);
+    }
+    if( x.flags & MEM_Int ){
+      iKey = x.u.i;
+    }else
+    if( (x.flags & MEM_Real)==0
+     || x.u.r < -9223372036854775808.0
+     || x.u.r > 9223372036854775807.0
+     || (double)(iKey = sqlite3RealToI64(x.u.r))!=x.u.r
+    ){
+      goto jump_to_p2;
+    }
     goto notExistsWithKey;
   }
   /* Fall through into OP_NotExists */
index a8d2fb2ffbdf291c724ae6c4f022a739f3fe5a62..305e7c903406f002c6a3903742dd029958cef7e8 100644 (file)
@@ -484,7 +484,7 @@ do_test intpkey-11.1 {
     SELECT b FROM t1 WHERE a=2.0+3.0;
   }
 } {hello}
-do_test intpkey-11.1 {
+do_test intpkey-11.2 {
   execsql {
     SELECT b FROM t1 WHERE a=2.0+3.5;
   }
@@ -642,4 +642,40 @@ do_execsql_test intpkey-17.2 {
   SELECT * FROM t17 ORDER BY +x;
 } {123 elephant 248 ostrich}
 
+# Forum post 2026-07-19T07:31:46Z
+#
+reset_db
+do_execsql_test intpkey-18.0 {
+  CREATE TABLE t1(x);
+  INSERT INTO t1(rowid,x) VALUES
+    (-9223372036854775808, 'min-int'),
+    (0, 'zero'),
+    (9223372036854775807, 'max-int');
+  SELECT rowid, * FROM t1 ORDER BY rowid;
+} {-9223372036854775808 min-int 0 zero 9223372036854775807 max-int}
+do_execsql_test intpkey-18.1 {
+  SELECT x FROM t1 WHERE rowid = -9223372036854775808;
+} {min-int}
+do_execsql_test intpkey-18.2 {
+  SELECT x FROM t1 WHERE rowid = -9223372036854775808.0;
+} {min-int}
+do_execsql_test intpkey-18.3 {
+  SELECT x FROM t1 WHERE rowid = -9223372036854775809.0;
+} {min-int}
+do_execsql_test intpkey-18.4 {
+  SELECT x FROM t1 WHERE rowid = -9223372036854777856.0;
+} {}
+do_execsql_test intpkey-18.5 {
+  SELECT x FROM t1 WHERE rowid = +9223372036854775807;
+} {max-int}
+do_execsql_test intpkey-18.6 {
+  SELECT x FROM t1 WHERE rowid = +9223372036854775807.0;
+} {max-int}
+do_execsql_test intpkey-18.7 {
+  SELECT x FROM t1 WHERE rowid = +9223372036854775808.0;
+} {max-int}
+do_execsql_test intpkey-18.8 {
+  SELECT x FROM t1 WHERE rowid = +9223372036854777856.0;
+} {}
+
 finish_test