Skip to content
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

textwrap.TextWrapper leaks two intermediate vars into class namespace #90702

Closed
sobolevn opened this issue Jan 27, 2022 · 2 comments
Closed

textwrap.TextWrapper leaks two intermediate vars into class namespace #90702

sobolevn opened this issue Jan 27, 2022 · 2 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 46544
Nosy @serhiy-storchaka, @sobolevn
PRs
  • bpo-46544: do not leak x and uspace in textwrap #30955
  • 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 = None
    created_at = <Date 2022-01-27.10:25:13.614>
    labels = ['type-bug', 'library', '3.11']
    title = '`textwrap.TextWrapper` leaks two intermediate vars into class namespace'
    updated_at = <Date 2022-01-27.11:56:07.690>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-01-27.11:56:07.690>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-01-27.10:25:13.614>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46544
    keywords = ['patch']
    message_count = 2.0
    messages = ['411849', '411859']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'sobolevn']
    pr_nums = ['30955']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46544'
    versions = ['Python 3.11']

    @sobolevn
    Copy link
    Member Author

    Right now this works:

    >>> import textwrap
    >>> textwrap.TextWrapper.x
    ' '
    >>> textwrap.TextWrapper.uspace
    32
    

    This happens because of these lines: https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L66-L69

    Notice that uspace and x are both undocumented, untested, and unused in our code.

    Similar variables in the same class body are then deleted from the scope:

        wordsep_simple_re = re.compile(r'(%s+)' % whitespace)
        del whitespace
    
    1. https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L99
    2. https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L106

    I propose to add del x, uspace as well. These two probably should not be leaking and should not be exposed.

    @sobolevn sobolevn added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 27, 2022
    @serhiy-storchaka
    Copy link
    Member

    New changeset 82bce54 by Nikita Sobolev in branch 'main':
    bpo-46544: Do not leak x and uspace in textwrap.TextWrapper (GH-30955)
    82bce54

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants