mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-44822: Don't truncate str
s with embedded NULL chars returned by sqlite3
UDF callbacks (GH-27588)
This commit is contained in:
parent
3e4cb7f40f
commit
8f010dc920
3 changed files with 41 additions and 3 deletions
|
@ -519,10 +519,17 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
|
|||
} else if (PyFloat_Check(py_val)) {
|
||||
sqlite3_result_double(context, PyFloat_AsDouble(py_val));
|
||||
} else if (PyUnicode_Check(py_val)) {
|
||||
const char *str = PyUnicode_AsUTF8(py_val);
|
||||
if (str == NULL)
|
||||
Py_ssize_t sz;
|
||||
const char *str = PyUnicode_AsUTF8AndSize(py_val, &sz);
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
if (sz > INT_MAX) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"string is longer than INT_MAX bytes");
|
||||
return -1;
|
||||
}
|
||||
sqlite3_result_text(context, str, (int)sz, SQLITE_TRANSIENT);
|
||||
} else if (PyObject_CheckBuffer(py_val)) {
|
||||
Py_buffer view;
|
||||
if (PyObject_GetBuffer(py_val, &view, PyBUF_SIMPLE) != 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue