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

Use PyMem_New instead of PyMem_Malloc #67634

Closed
serhiy-storchaka opened this issue Feb 11, 2015 · 8 comments
Closed

Use PyMem_New instead of PyMem_Malloc #67634

serhiy-storchaka opened this issue Feb 11, 2015 · 8 comments
Labels
extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 23446
Nosy @vstinner, @benjaminp, @skrah, @serhiy-storchaka
Files
  • pymem_new.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 = None
    closed_at = <Date 2015-02-16.14:31:52.409>
    created_at = <Date 2015-02-11.17:30:15.275>
    labels = ['extension-modules', 'interpreter-core', 'type-feature']
    title = 'Use PyMem_New instead of PyMem_Malloc'
    updated_at = <Date 2015-03-02.18:59:12.382>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-03-02.18:59:12.382>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-02-16.14:31:52.409>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules', 'Interpreter Core']
    creation = <Date 2015-02-11.17:30:15.275>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['38099']
    hgrepos = []
    issue_num = 23446
    keywords = ['patch']
    message_count = 8.0
    messages = ['235758', '235770', '235785', '235807', '235818', '236100', '237063', '237076']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'benjamin.peterson', 'Arfrever', 'skrah', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23446'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    Proposed patch replaces PyMem_Malloc with PyMem_New if the former is used in the form PyMem_Malloc(len * sizeof(type)). This can fix possible overflow errors and makes the code cleaner.

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Feb 11, 2015
    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Feb 11, 2015

    In _testbuffer.c: ndim <= 64, so the changes aren't really necessary.
    Somehow this fact needs to get widely known, since it does not make
    sense to check for overflow anytime ndim is used.

    The reason is of course that even an array with only 2 elements per
    dimension gets quite large with ndim=64. :)

    @benjaminp
    Copy link
    Contributor

    Very nice. I think you should also apply it to older versions, since (as we now) this sort of thing is very liable to cause security problems.

    @serhiy-storchaka
    Copy link
    Member Author

    In _testbuffer.c: ndim <= 64, so the changes aren't really necessary.

    Indeed, I'll remove these changes.

    The reason is of course that even an array with only 2 elements per
    dimension gets quite large with ndim=64. :)

    But an array can be with 1 element per dimension. In any case it is good that there is strict limitation on ndim values.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Feb 12, 2015

    Yes, but these (degenerate) arrays tend to arise only as a result of slicing.
    Last time I looked NumPy had MAX_NDIM=32, so we should be fine.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 16, 2015

    New changeset d83884b3a427 by Serhiy Storchaka in branch '2.7':
    Issue bpo-23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
    https://hg.python.org/cpython/rev/d83884b3a427

    New changeset 036a2aceae93 by Serhiy Storchaka in branch '3.4':
    Issue bpo-23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
    https://hg.python.org/cpython/rev/036a2aceae93

    New changeset d12c7938c4b0 by Serhiy Storchaka in branch 'default':
    Issue bpo-23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
    https://hg.python.org/cpython/rev/d12c7938c4b0

    @serhiy-storchaka
    Copy link
    Member Author

    May be apply the fix to 3.3?

    @benjaminp
    Copy link
    Contributor

    That would be nice.

    @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
    extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants