8000 bpo-44822: Don't truncate `str`s with embedded NULL chars returned by `sqlite3` UDF callbacks by erlend-aasland · Pull Request #27588 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44822: Don't truncate strs with embedded NULL chars returned by sqlite3 UDF callbacks #27588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-44822: Pass string size to sqlite3_result_text()
  • Loading branch information
Erlend E. Aasland committed Aug 4, 2021
commit 22417958afd9ee6b19c1f23276388c6a1df446db
11 changes: 8 additions & 3 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,15 @@ _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) {
sz = -1; // Let SQLite compute string length
}
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) {
Expand Down
0