From 97734af72d994cfd4f7dfcd87ba9c3df852af216 Mon Sep 17 00:00:00 2001 From: Timofey Lagutin Date: Sat, 10 Jan 2015 22:29:57 +0300 Subject: [PATCH] classpath-openjdk: Fix getZipFileEntry() 'addSlash' argument was incorrectly understood: it is supposed to add slash only on retry (see ZIP_GetEntry2() zip_util.c in OpenJDK). --- src/classpath-openjdk.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 6247eda6ca..a219ce3f2e 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -1576,6 +1576,10 @@ int64_t JNICALL ZipFile::Entry* find(ZipFile* file, const char* path, unsigned pathLength) { + if (pathLength > 0 && path[0] == '/') { + ++path; + --pathLength; + } unsigned i = hash(path) & (file->indexSize - 1); for (ZipFile::Entry* e = file->index[i]; e; e = e->next) { const uint8_t* p = e->start; @@ -1601,13 +1605,17 @@ int64_t JNICALL memcpy(RUNTIME_ARRAY_BODY(p), path->body().begin(), path->length()); RUNTIME_ARRAY_BODY(p)[path->length()] = 0; replace('\\', '/', RUNTIME_ARRAY_BODY(p)); - if (addSlash) { + + ZipFile::Entry *e = find(file, RUNTIME_ARRAY_BODY(p), path->length()); + + if (e == 0 and addSlash and RUNTIME_ARRAY_BODY(p)[path->length()] != '/') { RUNTIME_ARRAY_BODY(p)[path->length()] = '/'; RUNTIME_ARRAY_BODY(p)[path->length() + 1] = 0; + + e = find(file, RUNTIME_ARRAY_BODY(p), path->length()); } - return reinterpret_cast( - find(file, RUNTIME_ARRAY_BODY(p), path->length())); + return reinterpret_cast(e); } else { int64_t entry = cast(t,