Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve UNC-based MANIFEST classpath entries #736

Closed
jdeppe-pivotal opened this issue Dec 5, 2022 · 3 comments
Closed

Unable to resolve UNC-based MANIFEST classpath entries #736

jdeppe-pivotal opened this issue Dec 5, 2022 · 3 comments

Comments

@jdeppe-pivotal
Copy link

Very similar to #705 but where a MANIFEST classpath entry is detected in a jar in a UNC-based file.

So If I have a jar file with a MANIFEST classpath entry on a UNC file the classpath entries are not resolved to the UNC location. Here is a snippet from a debug log:

Dec 05, 2022 3:10:06 PM nonapi.io.github.classgraph.utils.LogNode flush
INFO: 2022-12-05T15:00:48.990-0800	ClassGraph	ClassGraph version 4.8.151
2022-12-05T15:00:48.992-0800	ClassGraph	Operating system: Windows 10 10.0 amd64
2022-12-05T15:00:48.992-0800	ClassGraph	Java version: 1.8.0_345 / 1.8.0_345-b01 (BellSoft)
2022-12-05T15:00:48.992-0800	ClassGraph	Java home: C:\Users\IEUser\.jdks\liberica-1.8.0_345\jre
2022-12-05T15:00:49.002-0800	ClassGraph	JRE rt.jar:
2022-12-05T15:00:49.002-0800	ClassGraph	-- C:/Users/IEUser/.jdks/liberica-1.8.0_345/jre/lib/rt.jar
2022-12-05T15:00:49.018-0800	ClassGraph	ScanSpec:
2022-12-05T15:00:49.018-0800	ClassGraph	-- packageAcceptReject: accept: ["org.springframework.shell"]; acceptPrefixes: ["", "/", "org.", "org.springframework.", "org.springframework.shell."]
2022-12-05T15:00:49.018-0800	ClassGraph	-- packagePrefixAcceptReject: acceptPrefixes: ["org.springframework.shell."]
2022-12-05T15:00:49.018-0800	ClassGraph	-- pathAcceptReject: accept: ["org/springframework/shell/"]; acceptPrefixes: ["", "/", "org/", "org/springframework/", "org/springframework/shell/"]
2022-12-05T15:00:49.018-0800	ClassGraph	-- pathPrefixAcceptReject: acceptPrefixes: ["org/springframework/shell/"]
2022-12-05T15:00:49.019-0800	ClassGraph	-- classAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- classfilePathAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- classPackageAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- classPackagePathAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- moduleAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- jarAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- classpathElementResourcePathAcceptReject: 
2022-12-05T15:00:49.019-0800	ClassGraph	-- libOrExtJarAcceptReject: 
2022-12-05T15:00:49.020-0800	ClassGraph	-- scanJars: true
2022-12-05T15:00:49.020-0800	ClassGraph	-- scanNestedJars: true
2022-12-05T15:00:49.020-0800	ClassGraph	-- scanDirs: true
2022-12-05T15:00:49.020-0800	ClassGraph	-- scanModules: true
2022-12-05T15:00:49.020-0800	ClassGraph	-- enableClassInfo: true
2022-12-05T15:00:49.020-0800	ClassGraph	-- enableFieldInfo: false
2022-12-05T15:00:49.020-0800	ClassGraph	-- enableMethodInfo: false
2022-12-05T15:00:49.021-0800	ClassGraph	-- enableAnnotationInfo: true
2022-12-05T15:00:49.021-0800	ClassGraph	-- enableStaticFinalFieldConstantInitializerValues: false
2022-12-05T15:00:49.021-0800	ClassGraph	-- enableInterClassDependencies: false
2022-12-05T15:00:49.021-0800	ClassGraph	-- enableExternalClasses: false
2022-12-05T15:00:49.021-0800	ClassGraph	-- enableSystemJarsAndModules: false
2022-12-05T15:00:49.022-0800	ClassGraph	-- ignoreClassVisibility: false
2022-12-05T15:00:49.022-0800	ClassGraph	-- ignoreFieldVisibility: false
2022-12-05T15:00:49.022-0800	ClassGraph	-- ignoreMethodVisibility: false
2022-12-05T15:00:49.022-0800	ClassGraph	-- disableRuntimeInvisibleAnnotations: false
2022-12-05T15:00:49.022-0800	ClassGraph	-- extendScanningUpwardsToExternalClasses: true
2022-12-05T15:00:49.022-0800	ClassGraph	-- allowedURLSchemes: null
2022-12-05T15:00:49.022-0800	ClassGraph	-- addedClassLoaders: null
2022-12-05T15:00:49.022-0800	ClassGraph	-- overrideClassLoaders: null
2022-12-05T15:00:49.022-0800	ClassGraph	-- addedModuleLayers: null
2022-12-05T15:00:49.022-0800	ClassGraph	-- overrideModuleLayers: null
2022-12-05T15:00:49.022-0800	ClassGraph	-- overrideClasspath: [\\ms\workspace\gemfire\geode-assembly\build\install\vmware-gemfire\lib\gfsh-dependencies.jar]
2022-12-05T15:00:49.023-0800	ClassGraph	-- classpathElementFilters: null
2022-12-05T15:00:49.023-0800	ClassGraph	-- initializeLoadedClasses: false
2022-12-05T15:00:49.023-0800	ClassGraph	-- removeTemporaryFilesAfterScan: false
2022-12-05T15:00:49.023-0800	ClassGraph	-- ignoreParentClassLoaders: false
2022-12-05T15:00:49.023-0800	ClassGraph	-- ignoreParentModuleLayers: false
2022-12-05T15:00:49.023-0800	ClassGraph	-- modulePathInfo: 
2022-12-05T15:00:49.024-0800	ClassGraph	-- maxBufferedJarRAMSize: 67108864
2022-12-05T15:00:49.024-0800	ClassGraph	-- enableMemoryMapping: false
2022-12-05T15:00:49.024-0800	ClassGraph	Number of worker threads: 1
2022-12-05T15:00:49.091-0800	ClassGraph	Finding classpath
2022-12-05T15:00:49.092-0800	ClassGraph	-- Finding classpath and modules
2022-12-05T15:00:49.130-0800	ClassGraph	---- Overriding classpath with: [\\ms\workspace\gemfire\geode-assembly\build\install\vmware-gemfire\lib\gfsh-dependencies.jar]
2022-12-05T15:00:49.130-0800	ClassGraph	------ Found classpath element: //ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/gfsh-dependencies.jar
2022-12-05T15:00:49.130-0800	ClassGraph	------ WARNING: when the classpath is overridden, there is no guarantee that the classes found by classpath scanning will be the same as the classes loaded by the context classloader
2022-12-05T15:00:49.148-0800	ClassGraph	Opening classpath elements (took 557.220269 sec)
2022-12-05T15:00:52.690-0800	ClassGraph	-- Opening classpath element file://ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/gfsh-dependencies.jar
2022-12-05T15:00:52.691-0800	ClassGraph	---- Opening jar: file://ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/gfsh-dependencies.jar
2022-12-05T15:01:03.169-0800	ClassGraph	------ Found Class-Path entry in manifest file: geode-wan-10.0.0-build.0.jar geode-connectors-10.0.0-build.0.jar geode-gfsh-10.0.0-build.0.jar geode-log4j-10.0.0-build.0.jar geode-rebalancer-10.0.0-build.0.jar geode-old-client-support-10.0.0-build.0.jar geode-memcached-10.0.0-build.0.jar geode-cq-10.0.0-build.0.jar geode-core-10.0.0-build.0.jar gemfire-version-10.0.0-build.0.jar geode-membership-10.0.0-build.0.jar geode-tcp-server-10.0.0-build.0.jar gemfire-tcp-messenger-10.0.0-build.0.jar geode-management-10.0.0-build.0.jar geode-serialization-10.0.0-build.0.jar geode-http-service-10.0.0-build.0.jar geode-logging-10.0.0-build.0.jar geode-common-10.0.0-build.0.jar geode-unsafe-10.0.0-build.0.jar gemfire-deployment-chained-classloader-10.0.0-build.0.jar spring-shell-1.2.0.RELEASE.jar spring-web-5.3.22.jar commons-lang3-3.12.0.jar rmiio-2.1.2.jar jackson-datatype-joda-2.13.4.jar jackson-annotations-2.13.4.jar jackson-core-2.13.4.jar jackson-datatype-jsr310-2.13.4.jar jackson-databind-2.13.4.2.jar swagger-annotations-2.2.2.jar jopt-simple-5.0.4.jar spring-context-5.3.22.jar spring-core-5.3.22.jar log4j-slf4j-impl-2.18.0.jar log4j-core-2.18.0.jar log4j-jcl-2.18.0.jar log4j-jul-2.18.0.jar httpclient-4.5.13.jar httpcore-4.4.15.jar HikariCP-4.0.3.jar jaxb-api-2.3.1.jar log4j-api-2.18.0.jar antlr-2.7.7.jar istack-commons-runtime-4.0.1.jar jaxb-impl-2.3.2.jar commons-validator-1.7.jar shiro-core-1.10.0.jar shiro-config-ogdl-1.10.0.jar commons-beanutils-1.9.4.jar commons-codec-1.15.jar commons-collections-3.2.2.jar commons-digester-2.1.jar commons-io-2.11.0.jar commons-logging-1.2.jar classgraph-4.8.151.jar micrometer-core-1.9.3.jar fastutil-8.5.8.jar javax.resource-api-1.7.1.jar jetty-webapp-9.4.48.v20220622.jar jetty-servlet-9.4.48.v20220622.jar jetty-security-9.4.48.v20220622.jar jetty-server-9.4.48.v20220622.jar javax.servlet-api-3.1.0.jar joda-time-2.11.0.jar jna-platform-5.11.0.jar jna-5.11.0.jar snappy-0.4.jar jgroups-3.6.14.Final.jar bson-4.7.1.jar shiro-cache-1.10.0.jar shiro-crypto-hash-1.10.0.jar shiro-crypto-cipher-1.10.0.jar shiro-config-core-1.10.0.jar shiro-event-1.10.0.jar shiro-crypto-core-1.10.0.jar shiro-lang-1.10.0.jar slf4j-api-1.7.36.jar netty-handler-4.1.79.Final.jar spring-beans-5.3.22.jar javax.activation-api-1.2.0.jar jline-2.12.jar spring-jcl-5.3.22.jar HdrHistogram-2.1.12.jar LatencyUtils-2.0.3.jar javax.transaction-api-1.3.jar netty-transport-native-unix-common-4.1.79.Final.jar netty-codec-4.1.79.Final.jar netty-transport-4.1.79.Final.jar netty-resolver-4.1.79.Final.jar netty-buffer-4.1.79.Final.jar netty-common-4.1.79.Final.jar jetty-xml-9.4.48.v20220622.jar jetty-http-9.4.48.v20220622.jar jetty-io-9.4.48.v20220622.jar jetty-util-ajax-9.4.48.v20220622.jar jetty-util-9.4.48.v20220622.jar
2022-12-05T15:10:06.378-0800	ClassGraph	-- Skipping invalid classpath entry /ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/geode-wan-10.0.0-build.0.jar : java.nio.file.NoSuchFileException: C:\ms\workspace\gemfire\geode-assembly\build\install\vmware-gemfire\lib\geode-wan-10.0.0-build.0.jar
2022-12-05T15:10:06.378-0800	ClassGraph	-- Skipping invalid classpath entry /ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/geode-connectors-10.0.0-build.0.jar : java.nio.file.NoSuchFileException: C:\ms\workspace\gemfire\geode-assembly\build\install\vmware-gemfire\lib\geode-connectors-10.0.0-build.0.jar
2022-12-05T15:10:06.378-0800	ClassGraph	-- Skipping invalid classpath entry /ms/workspace/gemfire/geode-assembly/build/install/vmware-gemfire/lib/geode-gfsh-10.0.0-build.0.jar : java.nio.file.NoSuchFileException: C:\ms\workspace\gemfire\geode-assembly\build\install\vmware-gemfire\lib\geode-gfsh-10.0.0-build.0.jar
[...snip...]

As you can see, the classpath entries are not resolved correctly.

@lukehutch
Copy link
Member

@jdeppe-pivotal Thanks for the report. I'm really low on time I can spend on ClassGraph right now, especially for Windows development (for the previous UNC bug it took several hours to get a Windows VM installed and working) -- any chance you could please step through to see where the additional slash is being dropped? This would be the place to start:

final String childClassPathEltPath = FastPathResolver.resolve(jarParentDir,

@jdeppe-pivotal
Copy link
Author

This diff gets things working for me. I'm not sure if this is the right thing to do here though. It's annoying that UNC paths are so ambiguous and don't have an explicit scheme associated with them.

diff --git a/src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java b/src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java
index 9f4bfeca..d776eb6f 100644
--- a/src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java
+++ b/src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java
@@ -178,7 +178,8 @@ public final class FileUtils {
         }

         // Handle "..", "." and empty path segments, if any were found
-        final boolean pathHasInitialSlash = pathLen > 0 && pathChars[0] == '/';
+        final boolean pathHasInitialSlash = pathChars[0] == '/';
+        final boolean pathHasInitialSlashSlash = pathHasInitialSlash && pathLen > 1 && pathChars[1] == '/';
         final StringBuilder pathSanitized = new StringBuilder(pathLen + 16);
         if (foundSegmentToSanitize) {
             // Sanitize between "!" section markers separately (".." should not apply past preceding "!")
@@ -231,6 +232,11 @@ public final class FileUtils {
             pathSanitized.append(path);
         }

+        // Intended to preserve the double slash at the start of UNC paths. Example: //server/file/path
+        if (pathHasInitialSlashSlash) {
+            pathSanitized.insert(0, '/');
+        }
+
         int startIdx = 0;
         if (removeInitialSlash || !pathHasInitialSlash) {
             // Strip off leading "/" if it needs to be removed, or if it wasn't present in the original path

lukehutch added a commit that referenced this issue Dec 10, 2022
@lukehutch
Copy link
Member

Thanks for figuring out the fix, looks good to me. Released in 4.8.152.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants