Petri Lehtinen committed e67715b

sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures

Closes #8033.

Comments (0)

Files changed (4)


     return None
 def func_returnblob():
     return b"blob"
+def func_returnlonglong():
+    return 1<<31
 def func_raiseexception():
     return type(v) is type(None)
 def func_isblob(v):
     return isinstance(v, (bytes, memoryview))
+def func_islonglong(v):
+    return isinstance(v, int) and v >= 1<<31
 class AggrNoStep:
     def __init__(self):
         self.con.create_function("returnfloat", 0, func_returnfloat)
         self.con.create_function("returnnull", 0, func_returnnull)
         self.con.create_function("returnblob", 0, func_returnblob)
+        self.con.create_function("returnlonglong", 0, func_returnlonglong)
         self.con.create_function("raiseexception", 0, func_raiseexception)
         self.con.create_function("isstring", 1, func_isstring)
         self.con.create_function("isfloat", 1, func_isfloat)
         self.con.create_function("isnone", 1, func_isnone)
         self.con.create_function("isblob", 1, func_isblob)
+        self.con.create_function("islonglong", 1, func_islonglong)
     def tearDown(self):
         self.assertEqual(type(val), bytes)
         self.assertEqual(val, b"blob")
+    def CheckFuncReturnLongLong(self):
+        cur = self.con.cursor()
+        cur.execute("select returnlonglong()")
+        val = cur.fetchone()[0]
+        self.assertEqual(val, 1<<31)
     def CheckFuncException(self):
         cur = self.con.cursor()
         val = cur.fetchone()[0]
         self.assertEqual(val, 1)
+    def CheckParamLongLong(self):
+        cur = self.con.cursor()
+        cur.execute("select islonglong(?)", (1<<42,))
+        val = cur.fetchone()[0]
+        self.assertEqual(val, 1)
 class AggregateTests(unittest.TestCase):
     def setUp(self):
         self.con = sqlite.connect(":memory:")
 Erik Demaine
 John Dennis
 Roger Dev
+Philippe Devalkeneer
 Raghuram Devarakonda
 Caleb Deveraux
 Catherine Devlin
+- Issue #8033: sqlite3: Fix 64-bit integer handling in user functions
+  on 32-bit architectures. Initial patch by Philippe Devalkeneer.
 - HTMLParser is now able to handle slashes in the start tag.
 - Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in


 void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
-    long longval;
     const char* buffer;
     Py_ssize_t buflen;
     } else if (py_val == Py_None) {
     } else if (PyLong_Check(py_val)) {
-        longval = PyLong_AsLong(py_val);
-        sqlite3_result_int64(context, (PY_LONG_LONG)longval);
+        sqlite3_result_int64(context, PyLong_AsLongLong(py_val));
     } else if (PyFloat_Check(py_val)) {
         sqlite3_result_double(context, PyFloat_AsDouble(py_val));
     } else if (PyUnicode_Check(py_val)) {
     sqlite3_value* cur_value;
     PyObject* cur_py_value;
     const char* val_str;
-    PY_LONG_LONG val_int;
     Py_ssize_t buflen;
     args = PyTuple_New(argc);
         cur_value = argv[i];
         switch (sqlite3_value_type(argv[i])) {
             case SQLITE_INTEGER:
-                val_int = sqlite3_value_int64(cur_value);
-                cur_py_value = PyLong_FromLong((long)val_int);
+                cur_py_value = PyLong_FromLongLong(sqlite3_value_int64(cur_value));
             case SQLITE_FLOAT:
                 cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value));
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.