Skip to content
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

gh-129603: Don't segfault if sqlite3.Row description is None #129604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Feb 3, 2025

@@ -151,9 +150,13 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
PyObject *item = PyTuple_GetItem(self->data, _idx);
return Py_XNewRef(item);
} else if (PyUnicode_Check(idx)) {
nitems = PyTuple_Size(self->description);
if (Py_IsNone(self->description)) {
PyErr_Format(PyExc_IndexError, "No item with key %R", idx);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this should be a KeyError, but that would create an inconsistency with L174. Moreover, we should also improve that error message by aligning it to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it should have been a dedicated exception type inheriting from LookupError but the ship has already sailed.

Now, since using the named field instead of its position is equivalent to row[get_index(field_name)], I think it's fine to keep the IndexError (even though it could be surprising at first).

Improving the error message may be good or documenting that an IndexError is raised for invalid indices or invalid keys (if it's not already done).

@erlend-aasland erlend-aasland force-pushed the sqlite/row-description-is-none branch from ae502d7 to 6f029cd Compare February 3, 2025 00:47
@erlend-aasland erlend-aasland added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Feb 3, 2025
@erlend-aasland erlend-aasland linked an issue Feb 3, 2025 that may be closed by this pull request
@erlend-aasland
Copy link
Contributor Author

Alternatively, we could disallow instantiation of Row objects if description is None, but I'm not sure it is a better approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault if pysqlite_Row->description == PyNone
2 participants