Repository navigation
[sqlite3] Do not truncate results of user functions and aggregates on the first NUL #88985
Description
Activity
The third argument to sqlite3_result_text() is the length of the string passed as the second argument. Currently, we pass -1, so SQLite has to invoke strlen() to compute the length of the passed string. Suggesting to use PyUnicode_AsUTF8AndSize() iso. PyUnicode_AsUTF8() and pass the string size to avoid the superfluous strlen().
See also:
- addedtype-featureA feature request or enhancementA feature request or enhancement3.11only security fixesonly security fixes
on Aug 4, 2021 - addedtype-featureA feature request or enhancementA feature request or enhancementextension-modulesC modules in the Modules dirC modules in the Modules dir3.11only security fixesonly security fixes
on Aug 4, 2021 - addedextension-modulesC modules in the Modules dirC modules in the Modules dir
on Aug 4, 2021 The difference between specifying negative and non-negative third argument of sqlite3_result_text() is that in the latter case the result can contain embedded NUL characters.
Could you please add a test for string containing embedded NUL?
Letting SQLite compute string length would work incorrect in case of embedded NULs, so I think that we should raise explicit error if sz > INT_MAX.
Could you please add a test for string containing embedded NUL?
Of course, thanks for the heads up.
I think that we should raise explicit error if sz > INT_MAX.
Yes, I thought about this. I do agree that raising OverflowError would be better. Thanks.
Serhiy, I've updated the PR, if you want to take a look. Thanks for your feedback.
- changed the title
[-][sqlite3] Micro-optimisation: pass string size to sqlite3_result_text()[/-][+][sqlite3] Do not truncate results of user functions and aggregates on the first NUL[/+]on Aug 4, 2021 - added3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorand removedtype-featureA feature request or enhancementA feature request or enhancement
on Aug 4, 2021 - changed the title
[-][sqlite3] Micro-optimisation: pass string size to sqlite3_result_text()[/-][+][sqlite3] Do not truncate results of user functions and aggregates on the first NUL[/+]on Aug 4, 2021 - addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorand removedtype-featureA feature request or enhancementA feature request or enhancement
on Aug 4, 2021 Thanks, Serhiy!
strs with embedded NULL chars returned bysqlite3UDF callbacks #27588strs with embedded NULL chars returned bysqlite3UDF callbacks (GH-27588) #27611strs with embedded NULL chars returned bysqlite3UDF callbacks (GH-27588) #27639Note: 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: