--- old/src/java.base/share/native/libzip/zip_util.c 2020-03-10 11:47:53.116764100 +0900 +++ new/src/java.base/share/native/libzip/zip_util.c 2020-03-10 11:47:52.245881700 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -101,7 +101,7 @@ ZFILE_Open(const char *fname, int flags) { #ifdef WIN32 WCHAR *wfname, *wprefixed_fname; - size_t converted_chars, fname_length; + size_t fname_length; jlong fhandle; const DWORD access = (flags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : @@ -135,10 +135,17 @@ flagsAndAttributes, /* flags and attributes */ NULL); } else { - if ((wfname = (WCHAR*)malloc((fname_length + 1) * sizeof(WCHAR))) == NULL) + /* Get required buffer size to convert to Unicode */ + int wfname_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, + fname, -1, NULL, 0); + if (wfname_len == 0) { return (jlong)INVALID_HANDLE_VALUE; - - if (mbstowcs_s(&converted_chars, wfname, fname_length + 1, fname, fname_length) != 0) { + } + if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) { + return (jlong)INVALID_HANDLE_VALUE; + } + if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, + fname, -1, wfname, wfname_len) == 0) { free(wfname); return (jlong)INVALID_HANDLE_VALUE; }