8000 unzOpen2_64() when it fails keeps file handle open · Issue #461 · zlib-ng/minizip-ng · GitHub
[go: up one dir, main page]

Skip to content

unzOpen2_64() when it fails keeps file handle open #461

Closed

Description

@jimpark

Using unzOpen2_64() with fill_win32_filefunc64() on a file that is not a Zip file causes the file to stay opened. Another process cannot delete the file. The problem is likely with fill_win32_filefunc64().

The issue is on Windows 10.

zlib_filefunc64_def ffunc;
fill_win32_filefunc64(&ffunc);
auto uzf = unzOpen2_64(path.c_str(), &ffunc);
if (uzf == nullptr) {
   return false; // The file handle to path is still open!
}

Activity

  1. jimpark commented on Apr 3, 2020

    @jimpark
    ContributorAuthor

    I think the fix is just a single line of code:

    unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
    {
        unzFile unz = NULL;
        void *stream = NULL;
    
        if (pzlib_filefunc_def)
        {
            if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
                return NULL;
        }
        else
        {
            if (mz_stream_os_create(&stream) == NULL)
                return NULL;
        }
    
        if (mz_stream_open(stream, path, MZ_OPEN_MODE_READ) != MZ_OK)
        {
            mz_stream_delete(&stream);
            return NULL;
        }
    
        unz = unzOpen_MZ(stream);
        if (unz == NULL)
        {
            mz_stream_close(stream); // <-- this needs to be added
            mz_stream_delete(&stream);
            return NULL;
        }
        return unz;
    }
    
  2. nmoinvaz commented on Apr 3, 2020

    @nmoinvaz
    Member

    Thank you for reporting the issue. The fix looks good, do you want to create a PR?

  3. added a commit that references this issue on Apr 3, 2020
    c30353f
  4. < 8000 div data-timeline-event-id="MDEyOklzc3VlQ29tbWVudDYwODU3MzY3NQ==" data-highlighted-event="false" class="shared__KSUE2D major__A5_AyP" data-testid="timeline-row-border-MDEyOklzc3VlQ29tbWVudDYwODU3MzY3NQ==">

    jimpark commented on Apr 3, 2020

    @jimpark
    ContributorAuthor
  • added a commit that references this issue on Apr 3, 2020
    08a196e
  • nmoinvaz commented on Apr 4, 2020

    @nmoinvaz
    Member

    Thanks!

  • Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      fixedIssue or bug has been fixed

      Type

      No type

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        0