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. jimpark commented on Apr 3, 2020

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

    @nmoinvaz
    Member

    Thanks!

  7. added
    fixed
    on Jan 10, 2021
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

    fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0