Skip to content

skipitem() in getargs.c still supports 'w' and 'w#', and shouldn't #68114

Closed

Description

@larryhastings
BPO 23926
Nosy @vstinner, @larryhastings, @serhiy-storchaka, @llllllllll
PRs
  • gh-68114: Fix handling for removed PyArg_ParseTuple formatters #8204
  • Files
  • skipitems.patch
  • skipitems.patch
  • 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 = 'https://github.com/larryhastings'
    closed_at = None
    created_at = <Date 2015-04-13.02:44:00.845>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = "skipitem() in getargs.c still supports 'w' and 'w#', and shouldn't"
    updated_at = <Date 2018-07-09.16:05:58.680>
    user = 'https://github.com/larryhastings'

    bugs.python.org fields:

    activity = <Date 2018-07-09.16:05:58.680>
    actor = 'llllllllll'
    assignee = 'larry'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2015-04-13.02:44:00.845>
    creator = 'larry'
    dependencies = []
    files = ['38972', '39931']
    hgrepos = []
    issue_num = 23926
    keywords = ['patch']
    message_count = 8.0
    messages = ['240587', '240794', '246780', '247383', '253226', '263709', '263776', '321300']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'larry', 'serhiy.storchaka', 'llllllllll']
    pr_nums = ['8204']
    priority = 'low'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23926'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. larryhastings commented on Apr 13, 2015

      @larryhastings
      ContributorAuthor

      tl;dr: skipitem() in Python 3 still supports "w" and "w#", which were abandoned. They should be removed.

      --

      If:

      • you have an extension that parses its arguments with
        PyArg_ParseTupleAndKeywords (or its cousins),
      • you have optional positional parameters, and
      • you run out of positional arguments

      CPython will call skipitem() to skip over the remaining positional parameters so it can process keyword arguments. It does this by knowing all the format units, and iterating over them and throwing away the various varargs pointers until it hits the keyword arguments part of the format string.

      PyArg_ParseTuple() etc. in Python 2 supported "w" and "w#" for parsing "objects with the read-write buffer interface". These were removed in Python 3.

      skipitem() in Python 3 still supports both skipping "w" and "w#". But in fact the only legal format unit starting with a 'w' in Python 3 is 'w*'. So a function with a 'w*' as an optional parameter that got skipped would be misinterpreted; skipitem would see the 'w', not recognize the following '*' and leave it there, then the next function that read a character from the format string (either skipitem() or convertsimple()) would see the '*' and throw an "impossible <bad format char>" exception.

    2. added
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Apr 13, 2015
    3. llllllllll commented on Apr 13, 2015

      llllllllllmannequin
      Mannequin

      here is a patch and test case.
      I added an entry to Misc/NEWS. I tried to follow the format; however, let me know if I have done this incorrectly.

    4. llllllllll commented on Jul 15, 2015

      llllllllllmannequin
      Mannequin

      Sorry it took so long to get back to this. I didn't realize this was still open. I have provided the update to the docs and moved it to the 3.6 section. I also made sure the patch still applies and the tests all pass.

    5. llllllllll commented on Jul 25, 2015

      llllllllllmannequin
      Mannequin

      bumping so that we don't forget about this.

    6. llllllllll commented on Oct 20, 2015

      llllllllllmannequin
      Mannequin

      bumping this issue

    7. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Oct 20, 2015
    8. llllllllll commented on Apr 19, 2016

      llllllllllmannequin
      Mannequin

      bump

    9. vstinner commented on Apr 19, 2016

      @vstinner
      Member

      I reviewed skipitems.patch.

    10. serhiy-storchaka commented on Jul 9, 2018

      @serhiy-storchaka
      Member

      Do you mind to convert your patch into a pull request Joe?

    11. transferred this issue fromon Apr 10, 2022
    12. added a commit that references this issue on Apr 23, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)end of life3.8 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions