Author: markt
Date: Tue Sep 12 13:54:01 2017
New Revision: 1808116

URL: http://svn.apache.org/viewvc?rev=1808116&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=61503
This corrects a potential regression in the fix for bug 60940 with an 
alternative solution that adds the JarEntry objects normally skipped by a 
JarInputStream only if those entries exist.

Added:
    
tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java   
(with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java?rev=1808116&r1=1808115&r2=1808116&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarWarResourceSet.java 
Tue Sep 12 13:54:01 2017
@@ -106,29 +106,26 @@ public class JarWarResourceSet extends A
                     JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
                     jarFileIs = warFile.getInputStream(jarFileInWar);
 
-                    try (JarInputStream jarIs = new JarInputStream(jarFileIs)) 
{
+                    try (TomcatJarInputStream jarIs = new 
TomcatJarInputStream(jarFileIs)) {
                         JarEntry entry = jarIs.getNextJarEntry();
-                        boolean hasMetaInf = false;
                         while (entry != null) {
-                            if (!hasMetaInf && 
entry.getName().startsWith("META-INF/")) {
-                                hasMetaInf = true;
-                            }
                             archiveEntries.put(entry.getName(), entry);
                             entry = jarIs.getNextJarEntry();
                         }
                         setManifest(jarIs.getManifest());
-                        // Hacks to work-around JarInputStream swallowing these
-                        // entries. The attributes for these entries will be
-                        // incomplete. Making the attributes available would
-                        // require (re-)reading the stream as a ZipInputStream
-                        // and creating JarEntry objects from the ZipEntries.
-                        if (hasMetaInf) {
-                            JarEntry metaInfDir = new JarEntry("META-INF/");
-                            archiveEntries.put(metaInfDir.getName(), 
metaInfDir);
+                        // Hack to work-around JarInputStream swallowing these
+                        // entries. TomcatJarInputStream is used above which
+                        // extends JarInputStream and the method that creates
+                        // the entries over-ridden so we can a) tell if the
+                        // entries are present and b) cache them so we can
+                        // access them here.
+                        entry = jarIs.getMetaInfEntry();
+                        if (entry != null) {
+                            archiveEntries.put(entry.getName(), entry);
                         }
-                        if (jarIs.getManifest() != null) {
-                            JarEntry manifest = new 
JarEntry("META-INF/MANIFEST.MF");
-                            archiveEntries.put(manifest.getName(), manifest);
+                        entry = jarIs.getManifestEntry();
+                        if (entry != null) {
+                            archiveEntries.put(entry.getName(), entry);
                         }
                     }
                 } catch (IOException ioe) {

Added: 
tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java?rev=1808116&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java 
(added)
+++ 
tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java 
Tue Sep 12 13:54:01 2017
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.webresources;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.zip.ZipEntry;
+
+/**
+ * The purpose of this sub-class is to obtain references to the JarEntry 
objects
+ * for META-INF/ and META-INF/MANIFEST.MF that are otherwise swallowed by the
+ * JarInputStream implementation.
+ */
+public class TomcatJarInputStream extends JarInputStream {
+
+    private JarEntry metaInfEntry;
+    private JarEntry manifestEntry;
+
+
+    TomcatJarInputStream(InputStream in) throws IOException {
+        super(in);
+    }
+
+
+    @Override
+    protected ZipEntry createZipEntry(String name) {
+        ZipEntry ze = super.createZipEntry(name);
+        if (metaInfEntry == null && "META-INF/".equals(name)) {
+            metaInfEntry = (JarEntry) ze;
+        } else if (manifestEntry == null && 
"META-INF/MANIFESR.MF".equals(name)) {
+            manifestEntry = (JarEntry) ze;
+        }
+        return ze;
+    }
+
+
+    JarEntry getMetaInfEntry() {
+        return metaInfEntry;
+    }
+
+
+    JarEntry getManifestEntry() {
+        return manifestEntry;
+    }
+}

Propchange: 
tomcat/trunk/java/org/apache/catalina/webresources/TomcatJarInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1808116&r1=1808115&r2=1808116&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Sep 12 13:54:01 2017
@@ -81,6 +81,12 @@
         3875) optional and disabled by default. Based on a patch by jm009.
         (markt)
       </add>
+      <fix>
+        <bug>61503</bug>: This corrects a potential regression in the fix for
+        <bug>60940</bug> with an alternative solution that adds the
+        <code>JarEntry</code> objects normally skipped by a
+        <code>JarInputStream</code> only if those entries exist. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to