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

plistlib crashes too easily on bad files #40507

Closed
jackjansen opened this issue Jul 4, 2004 · 8 comments
Closed

plistlib crashes too easily on bad files #40507

jackjansen opened this issue Jul 4, 2004 · 8 comments
Assignees
Labels
easy OS-mac type-bug An unexpected behavior, bug, or error

Comments

@jackjansen
Copy link
Member

BPO 985064
Nosy @jackjansen, @birkenfeld, @ronaldoussoren, @ned-deily, @ezio-melotti, @merwok, @mher
Dependencies
  • bpo-775321: plistlib error handling
  • Files
  • plist_validation.diff: patch for validation
  • plist_validation_v2.diff: 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/ned-deily'
    closed_at = <Date 2011-05-28.10:19:39.727>
    created_at = <Date 2004-07-04.21:30:29.000>
    labels = ['OS-mac', 'easy', 'type-bug']
    title = 'plistlib crashes too easily on bad files'
    updated_at = <Date 2011-05-28.10:19:39.725>
    user = 'https://github.com/jackjansen'

    bugs.python.org fields:

    activity = <Date 2011-05-28.10:19:39.725>
    actor = 'ned.deily'
    assignee = 'ned.deily'
    closed = True
    closed_date = <Date 2011-05-28.10:19:39.727>
    closer = 'ned.deily'
    components = ['macOS']
    creation = <Date 2004-07-04.21:30:29.000>
    creator = 'jackjansen'
    dependencies = ['775321']
    files = ['19996', '20258']
    hgrepos = []
    issue_num = 985064
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['60527', '123725', '123758', '125333', '125341', '126089', '137115', '137116']
    nosy_count = 9.0
    nosy_names = ['jackjansen', 'georg.brandl', 'jvr', 'ronaldoussoren', 'ned.deily', 'ezio.melotti', 'eric.araujo', 'mher', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue985064'
    versions = ['Python 3.1', 'Python 3.2', 'Python 3.3']

    @jackjansen
    Copy link
    Member Author

    Plistlib doesn't do much error checking, and it can crash on bad
    input. Moreover, it doesn't provide much help if it does crash (no
    linenumbers, etc).

    The problem I ran into was a dangling <key>foo</key>. After this
    key the dict ended, but the next entry in the surrounding
    datastructure, an array, picked up the key from self.currentKey
    and crashed in addObject().

    I was about to fix this when I noticed that there's lots of problems
    with <key> handling, duplicates or missing ones aren't detected
    either and can cause crashes too. It may be better to put a general
    try/except in parse() and print a line number or something in case
    of a failure.

    @devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Feb 14, 2009
    @devdanzin devdanzin mannequin added easy labels Apr 22, 2009
    @mher
    Copy link
    Mannequin

    mher mannequin commented Dec 10, 2010

    The attached patch fixes crashes on bad input. The patch implements validation for dict and array elements as well as some resource cleanup. The tests are included as well.

    @ned-deily
    Copy link
    Member

    One review comment: the patch adds a new exception class that is used for the errors that are now additionally detected. Elsewhere plistlib uses non-specific exception classes like ValueError. If starting from scratch, it might be better to consistently use a specific exception class but that would create incompatibilities if changed now. I don't see a compelling need to add one now just for these errors. (But, if kept, it should be added to the docs.) Otherwise, looks good to me.

    Thanks for taking this on!

    @mher
    Copy link
    Mannequin

    mher mannequin commented Jan 4, 2011

    I've replaced plistlib.InvalidPlistError with ValueError

    @birkenfeld
    Copy link
    Member

    LGTM.

    @merwok
    Copy link
    Member

    merwok commented Jan 12, 2011

    See also reopened dependency bpo-775321.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 28, 2011

    New changeset a2688e252204 by Ned Deily in branch '3.1':
    Issue bpo-985064: Make plistlib more resilient to faulty input plists.
    http://hg.python.org/cpython/rev/a2688e252204

    New changeset f555d959a5d7 by Ned Deily in branch '3.2':
    Issue bpo-985064: Make plistlib more resilient to faulty input plists.
    http://hg.python.org/cpython/rev/f555d959a5d7

    New changeset d0bc18a50bd1 by Ned Deily in branch 'default':
    Issue bpo-985064: Make plistlib more resilient to faulty input plists.
    http://hg.python.org/cpython/rev/d0bc18a50bd1

    @ned-deily
    Copy link
    Member

    Thank you for the patch and tests! Applied in 3.1 (for 3.1.4), 3.2 (for 3.2.1), and 3.3. (The 2.x version of plistlib differs somewhat from the 3.x version so the patch would need some rework and testing for 2.7; that is probably not worth the effort at this point.)

    @ned-deily ned-deily self-assigned this May 28, 2011
    @ned-deily ned-deily self-assigned this May 28, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy OS-mac type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants