# HG changeset patch # User mbaesken # Date 1548345067 -3600 # Thu Jan 24 16:51:07 2019 +0100 # Node ID 58578e24f1da5cb6b4abfdf2c9ecc38c6b2e4041 # Parent 50355c3d35c06b3402f2e54c1cfbe6c0cdbaa03c 8217093: Support extended-length paths in parse_manifest.c on windows diff --git a/src/java.base/share/native/libjli/parse_manifest.c b/src/java.base/share/native/libjli/parse_manifest.c --- a/src/java.base/share/native/libjli/parse_manifest.c +++ b/src/java.base/share/native/libjli/parse_manifest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2019, 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 @@ -362,9 +362,11 @@ bp = buffer; if (find_positions(fd, bp, &base_offset, &censtart) == -1) { + free(buffer); return -1; } if (JLI_Lseek(fd, censtart, SEEK_SET) < (jlong) 0) { + free(buffer); return -1; } @@ -562,6 +564,12 @@ return (1); } +#ifdef _WIN32 +int open_jarfile(const char* name, int flags); +#else +int open_jarfile(const char* name, int flags) { return open(name, flags); } +#endif + /* * Read the manifest from the specified jar file and fill in the manifest_info * structure with the information found within. @@ -583,7 +591,7 @@ int rc; char *splashscreen_name = NULL; - if ((fd = open(jarfile, O_RDONLY + if ((fd = open_jarfile(jarfile, O_RDONLY #ifdef O_LARGEFILE | O_LARGEFILE /* large file mode */ #endif @@ -640,7 +648,7 @@ zentry entry; void *data = NULL; - if ((fd = open(jarfile, O_RDONLY + if ((fd = open_jarfile(jarfile, O_RDONLY #ifdef O_LARGEFILE | O_LARGEFILE /* large file mode */ #endif @@ -688,7 +696,7 @@ char *value; int rc; - if ((fd = open(jarfile, O_RDONLY + if ((fd = open_jarfile(jarfile, O_RDONLY #ifdef O_LARGEFILE | O_LARGEFILE /* large file mode */ #endif diff --git a/src/java.base/windows/native/libjli/parse_manifest_md.c b/src/java.base/windows/native/libjli/parse_manifest_md.c new file mode 100644 --- /dev/null +++ b/src/java.base/windows/native/libjli/parse_manifest_md.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1997, 2019, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include +#include +#include +#include "jni.h" +#include "jli_util.h" + +/* On Windows, if _open fails, retry again with CreateFileW and + * "\\?\" prefix ( extended-length paths) - this allows to open paths with larger file names; + * otherwise we run into the MAX_PATH limitation */ +int open_jarfile(const char* name, int flags) { + int fd = _open(name, flags); + if (fd == -1 && ENOENT == errno) { + #define ELP_PREFIX L"\\\\?\\" + wchar_t* wname = NULL; + wchar_t* wfullname = NULL; + wchar_t* wfullname_with_prefix = NULL; + size_t wnamelen; + size_t wfullnamelen; + HANDLE h; + + wnamelen = strlen(name) + 1; + wname = (wchar_t*) malloc(wnamelen * sizeof(wchar_t)); + if (wname == NULL) { + goto end; + } + if (mbstowcs(wname, name, wnamelen - 1) == -1) { + goto end; + } + wname[wnamelen - 1] = L'\0'; + wfullname = _wfullpath(wfullname, wname, 0); + if (wfullname == NULL) { + goto end; + } + + wfullnamelen = wcslen(wfullname); + wfullname_with_prefix = (wchar_t*) malloc((wcslen(ELP_PREFIX) + wfullnamelen + 1) + * sizeof(wchar_t)); + wcscpy(wfullname_with_prefix, ELP_PREFIX); + wcscpy(wfullname_with_prefix + wcslen(ELP_PREFIX), wfullname); + + h = CreateFileW(wfullname_with_prefix, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + goto end; + } + /* associates fd with handle */ + fd = _open_osfhandle((intptr_t)h, _O_RDONLY); +end: + free(wname); + free(wfullname); + free(wfullname_with_prefix); + } + return fd; +}