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

tempfile crashes #37324

Closed
theller opened this issue Oct 15, 2002 · 15 comments
Closed

tempfile crashes #37324

theller opened this issue Oct 15, 2002 · 15 comments
Assignees

Comments

@theller
Copy link

theller commented Oct 15, 2002

BPO 623464
Nosy @tim-one, @theller
Files
  • posixmodule.c.diff: Patch for posixmodule.c
  • 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/theller'
    closed_at = <Date 2002-11-07.16:12:12.000>
    created_at = <Date 2002-10-15.09:54:30.000>
    labels = ['OS-windows']
    title = 'tempfile crashes'
    updated_at = <Date 2002-11-07.16:12:12.000>
    user = 'https://github.com/theller'

    bugs.python.org fields:

    activity = <Date 2002-11-07.16:12:12.000>
    actor = 'theller'
    assignee = 'theller'
    closed = True
    closed_date = None
    closer = None
    components = ['Windows']
    creation = <Date 2002-10-15.09:54:30.000>
    creator = 'theller'
    dependencies = []
    files = ['632']
    hgrepos = []
    issue_num = 623464
    keywords = []
    message_count = 15.0
    messages = ['12781', '12782', '12783', '12784', '12785', '12786', '12787', '12788', '12789', '12790', '12791', '12792', '12793', '12794', '12795']
    nosy_count = 3.0
    nosy_names = ['tim.peters', 'nnorwitz', 'theller']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue623464'
    versions = ['Python 2.3']

    @theller
    Copy link
    Author

    theller commented Oct 15, 2002

    tempfile.NamedTemporaryFile(".zip") crashes with an
    access violation. Win2k, SP2.

    @theller theller closed this as completed Oct 15, 2002
    @theller theller self-assigned this Oct 15, 2002
    @theller theller closed this as completed Oct 15, 2002
    @theller theller self-assigned this Oct 15, 2002
    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Oct 17, 2002

    Logged In: YES
    user_id=33168

    Note: You probably want:
    tempfile.NamedTemporaryFile(suffix=".zip")

    I tried this under Linux and get: OSError: [Errno 22]
    Invalid argument

    So this appears to be windows specific. Exactly which line
    is causing the crash? os.fdopen?

    @theller
    Copy link
    Author

    theller commented Oct 18, 2002

    Logged In: YES
    user_id=11105

    It crashes in fdopen - looks like a bug in MS runtime library:

    (in file vc98\crt\src\fdopen.c)
    fdopen calls _tfopen(), creates a FILE *stream, and if the first
    character in mode is not r, w, or a, sets 'stream' to NULL to
    signal an error. Then it calls _unlock_str(stream), which
    crashes.

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Nov 2, 2002

    Logged In: YES
    user_id=33168

    We don't check anywhere else for valid mode chars. We would
    have to fix Modules/posixmodule.c and Modules/socketmodule
    if we wanted to check. Thomas, do you think a checks should
    be added or close this as a 3rd party problem?

    @theller
    Copy link
    Author

    theller commented Nov 4, 2002

    Logged In: YES
    user_id=11105

    IMO we should check for a valid mode. There is a large
    surprise if python crashes with an access violation when the
    innocent user does innocent things like this. But this is just
    *my* opinion.

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Nov 4, 2002

    Logged In: YES
    user_id=33168

    Sounds good to me. Care to work on a patch with tests?

    @tim-one
    Copy link
    Member

    tim-one commented Nov 4, 2002

    Logged In: YES
    user_id=31435

    We generally don't check for valid mode characters
    because C allows implementations to extend the standard
    set, there's no way to query the platform about which mode
    extensions it supports, and we don't want to block users
    from using platform-specific mode extensions.

    It would be OK by me if we insisted that the first character
    be in "rwa", but checking more than that is off limits. Note
    that Windows simply ignores all of the mode chars starting
    with the first one it doesn't recognize:

    >>> f = open('example.txt', 'what a crock this mode string 
    is!')
    >>> f
    <open file 'example.txt', mode 'what a crock this mode 
    string is!' at 0x00651870
    >
    >>>

    That was the same as passing "w".

    @theller
    Copy link
    Author

    theller commented Nov 5, 2002

    Logged In: YES
    user_id=11105

    Here's a patch for Modules/posixmodule.c, which fixes this
    particular issue, conforming to Tim's requirements.

    @tim-one
    Copy link
    Member

    tim-one commented Nov 5, 2002

    Logged In: YES
    user_id=31435

    Cool! One thing: drop the Windows #ifdef. I asked Guido,
    and he agrees that Python wants to enforce this requirement
    on all platforms.

    @theller
    Copy link
    Author

    theller commented Nov 5, 2002

    Logged In: YES
    user_id=11105

    Great, will do this tomorrow. What about socketmodule.c,
    which Neal mentioned?

    @tim-one
    Copy link
    Member

    tim-one commented Nov 5, 2002

    Logged In: YES
    user_id=31435

    If socketmodule isn't crashing, I'd leave it alone.

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Nov 5, 2002

    Logged In: YES
    user_id=33168

    Thomas, I belivee the code below will check if the other
    cases crash.

    # test posixmodule.popen(), 
    # would need check around line 2835
    # as first code in popen()
    import posix
    # you may need a command that works, 
    # I'm guessing cmd.exe is ok
    posix.popen('cmd.exe', '.zip')
    
    # test socketmodule.sock_makefile(), 
    # would need check around line 1572
    # after PyArg_ParseTuple
    from socket import *
    s = socket(AF_INET, SOCK_STREAM)
    s.makefile('.zip')

    @theller
    Copy link
    Author

    theller commented Nov 7, 2002

    Logged In: YES
    user_id=11105

    I couldn't get it to crash with Neil's code, so I checked it in
    without the Windows #ifdef: posixmodule.c, rev 2.271.

    BTW: I always assume we don't need NEWS entries for bug
    fixes, is this correct?

    @tim-one
    Copy link
    Member

    tim-one commented Nov 7, 2002

    Logged In: YES
    user_id=31435

    Thanks! You certainly need a NEWS item for this, and
    possibly even a doc change, since requiring that mode
    strings begin with certain letters is a new language
    requirement. However unlikely, *somebody* may have code
    out there that will break because of it.

    @theller
    Copy link
    Author

    theller commented Nov 7, 2002

    Logged In: YES
    user_id=11105

    Sigh, even more work.
    In this case, it cannot be called a bugfix anymore...

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants