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
[sqlite3] sqlite3_column_name() failures should raise MemoryError #87417
Comments
AFAICS, the docs for sqlite3_column_name() says that if it returns NULL, we are out of memory, thus we should call PyErr_NoMemory() and bail. FYI, there are the calls to sqlite3_column_name() in Modules/_sqlite//cursor.c Ref: |
Well, it returns NULL in case of out of memory, but is it the only cause? Can NULL be returned for other reasons? |
According to the SQLite docs, no. Looking at the source code, we see that it also returns NULL if the second parameter (column index) is out of range, but we already check that. AFAICS, the only reason for a NULL in our case is OOM. |
It also returns NULL if the column name was not set (is it even possible?). |
That's inside sqlite3_value_text() and friends, then? Let's investigate further before concluding. |
Investigate where column names are initialized and whether is it possible to get them NULLs. The array of column names is filled with NULLs when initialized and later it is filled with references to strings. I am wondering whether there is a gap between this which lefts some column names as NULLs. |
"SELECT 1" yields "1" as column name. We can't set the column name via the API, so that's pretty much it (implicit name or explicit through the AS keyword). As long as sqlite3_prepare_v2() returned SQLITE_OK, it seems that SQLite assures we've got a valid column name. As far as I can sqlite3_column_name() returns NULL if:
We've got 1) and 2) covered. SQLite has a pretty good code coverage, so I'd say 4) is unlikely. What do you think? |
Please go ahead! |
Will do. Thanks for pushing the investigation. |
After discussing the matter briefly on the SQLite forum, I'm no longer 100% certain about this. There seems to be uncertainty about which other conditions can produce NULL, although memory error seems to be the most probable. I consider closing both this issue and the PR and just leave the code as it is. |
Could you please give a link to the discussion? |
Sure! Here it is: https://sqlite.org/forum/forumpost/574c6bc66c |
Larry Brasfield's comment https://sqlite.org/forum/forumpost/6430fc589d?t=h aligns with https://bugs.python.org/issue43251#msg387428 I'll think twice before posting there again, though. |
I believe we can proceed with this as planned. Serhiy, do you have additional comments or change requests? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: