Skip to content

[sqlite3] Fix sqlite3_value_blob() usage #87462

Closed

Description

@erlend-aasland
BPO 43296
Nosy @berkerpeksag, @serhiy-storchaka, @erlend-aasland
PRs
  • bpo-43296: Handle sqlite3_value_blob() errors #24674
  • 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:

    assignee = None
    closed_at = <Date 2021-04-14.21:09:30.879>
    created_at = <Date 2021-02-22.14:37:13.837>
    labels = ['type-bug', 'library', '3.10']
    title = '[sqlite3] Fix sqlite3_value_blob() usage'
    updated_at = <Date 2021-04-14.21:15:00.455>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-04-14.21:15:00.455>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-14.21:09:30.879>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2021-02-22.14:37:13.837>
    creator = 'erlendaasland'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43296
    keywords = ['patch']
    message_count = 5.0
    messages = ['387516', '387541', '387719', '391100', '391101']
    nosy_count = 3.0
    nosy_names = ['berker.peksag', 'serhiy.storchaka', 'erlendaasland']
    pr_nums = ['24674']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43296'
    versions = ['Python 3.10']

    Activity

    1. erlend-aasland commented on Feb 22, 2021

      @erlend-aasland
      ContributorAuthor

      The sqlite3_value_() API is almost identical to the sqlite3_column_() API. sqlite3_value_bytes() should be called after we've converted the value using sqlite3_value_blob().

      See also bpo-43249.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Feb 22, 2021
    3. erlend-aasland commented on Feb 22, 2021

      @erlend-aasland
      ContributorAuthor

      Related:
      If sqlite3_value_blob() returns NULL, we should check if sqlite3_errcode() equals SQLITE_NOMEM and raise MemoryError if it does.

      If not, we should initialise cur_py_value to None, because as the PyBytes_FromStringAndSize docs says: "If v is NULL, the contents of the bytes object are uninitialized."

    4. changed the title [-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-] [+][sqlite3] Fix sqlite3_value_blob() usage[/+] on Feb 26, 2021
    5. changed the title [-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-] [+][sqlite3] Fix sqlite3_value_blob() usage[/+] on Feb 26, 2021
    6. erlend-aasland commented on Feb 26, 2021

      @erlend-aasland
      ContributorAuthor

      If sqlite3_value_blob() returns NULL, we should check if sqlite3_errcode() equals SQLITE_NOMEM and raise MemoryError if it does.

      This also applies to sqlite3_value_text().

      It also applies to sqlite3_value_bytes() if a conversion takes place. We don't need to care about that as long as we call sqlite3_value_bytes() after conversion.

      Also, PyTuple_SetItem() errors are not checked.

      I would also suggest using PyUnicode_FromStringAndSize() iso. PyUnicode_FromString() in case SQLITE_TEXT, to avoid the unneeded strlen(). After sqlite3_value_text() is called, we can just use sqlite3_value_bytes(), since the length is precomputed as a result of the conversion.

      Berker, would you allow a PR to improve all these issues in _pysqlite_build_py_params(), or would you prefer them split up in multiple PR's?

    7. berkerpeksag commented on Apr 14, 2021

      @berkerpeksag
      Member

      New changeset 5cb601f by Erlend Egeberg Aasland in branch 'master':
      bpo-43296: Handle sqlite3_value_blob() errors (GH-24674)
      5cb601f

    8. erlend-aasland commented on Apr 14, 2021

      @erlend-aasland
      ContributorAuthor

      Thanks, Berker!

      I'll add separate issues for sqlite3_value_text() and the missing PyTuple_SetItem() error checks.

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions