Skip to content

Check index in PyTuple_GET_ITEM/PyTuple_SET_ITEM in debug mode #79518

Closed

Description

@vstinner
BPO 35337
Nosy @scoder, @vstinner, @skrah, @serhiy-storchaka, @ZackerySpytz
PRs
  • bpo-35337: Fix gettmarg(): use PyStructSequence_GET_ITEM() #10765
  • bpo-35337: PyTuple_GET_ITEM() now checks the index #10766
  • 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 2018-12-17.11:22:21.208>
    created_at = <Date 2018-11-28.13:17:08.129>
    labels = ['interpreter-core', '3.8']
    title = 'Check index in PyTuple_GET_ITEM/PyTuple_SET_ITEM in debug mode'
    updated_at = <Date 2018-12-17.11:22:21.206>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-12-17.11:22:21.206>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-17.11:22:21.208>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2018-11-28.13:17:08.129>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35337
    keywords = ['patch']
    message_count = 12.0
    messages = ['330597', '330598', '330600', '330638', '330675', '330676', '331408', '331410', '331425', '331429', '331431', '331986']
    nosy_count = 5.0
    nosy_names = ['scoder', 'vstinner', 'skrah', 'serhiy.storchaka', 'ZackerySpytz']
    pr_nums = ['10765', '10766']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35337'
    versions = ['Python 3.8']

    Activity

    1. vstinner commented on Nov 28, 2018

      @vstinner
      MemberAuthor

      I propose to add assertions to PyTuple_GET_ITEM/PyTuple_SET_ITEM in debug mode to check the index when Python is compiled in debug mode (./configure --with-pydebug).

      This change is backward incompatible when PyTuple_GET_ITEM/PyTuple_SET_ITEM is used on a structseq with unnamed fields. Well, that's a bug in the user code, PyStructSequence_GET_ITEM/PyStructSequence_SET_ITEM should be used instead.

    2. vstinner commented on Nov 28, 2018

      @vstinner
      MemberAuthor

      My commit df108dc already added assert(PyTuple_Check(op)) to these two macros.

    3. vstinner commented on Nov 28, 2018

      @vstinner
      MemberAuthor

      New changeset 1cdfcfc by Victor Stinner in branch 'master':
      bpo-35337: Fix gettmarg(): use PyStructSequence_GET_ITEM() (GH-10765)
      1cdfcfc

    4. ZackerySpytz commented on Nov 28, 2018

      ZackerySpytzmannequin
      Mannequin

      See also bpo-14614.

    5. serhiy-storchaka commented on Nov 29, 2018

      @serhiy-storchaka
      Member

      This is compatibility breaking change. Currently you can get the address of the array of tuple items by using &PyTuple_GET_ITEM(obj, 0).

    6. vstinner commented on Nov 29, 2018

      @vstinner
      MemberAuthor

      This is compatibility breaking change.

      Right. The question is if you are ok with it :-)

      Currently you can get the address of the array of tuple items by using &PyTuple_GET_ITEM(obj, 0).

      I don't get your point. I know that you access directly obj->ob_item to use directly the C array rather than PyTuple_GET_ITEM/PyTuple_SET_ITEM, but the issue is about making PyTuple_GET_ITEM/PyTuple_SET_ITEM stricter in debug mode.

    7. serhiy-storchaka commented on Dec 9, 2018

      @serhiy-storchaka
      Member

      I think we can break this only after adding public API for accessing internal storage of a tuple: PyTuple_ITEMS().

      And the same for lists.

    8. scoder commented on Dec 9, 2018

      @scoder
      Contributor

      If this is really just about debugging, then I would suggest to not break existing code at all.

    9. skrah commented on Dec 9, 2018

      skrahmannequin
      Mannequin

      I'm using &PyTuple_GET_ITEM(args, 0), so Serhiy's concern is not theoretical.

      I think if people want the safe version they should use PyTuple_GetItem().

    10. skrah commented on Dec 9, 2018

      skrahmannequin
      Mannequin

      Since this feature mainly helps when running a test suite using a debug build:

      The same can be achieved by running the test suite under Valgrind, which catches invalid accesses and a lot more.

      So I'd prefer to keep the macro in its current form.

    11. skrah commented on Dec 9, 2018

      skrahmannequin
      Mannequin

      If the feature is for the Python test suite itself, one solution would be to add -DPY_BOUNDS_CHECKS and use that on the buildbots.

      I still think making all of the test suite Valgrind-ready (most of it is, except test_multiprocessing and a few others) would catch more.

    12. vstinner commented on Dec 17, 2018

      @vstinner
      MemberAuthor

      Ok, I abandon my change.

    13. 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.8 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions