commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1395004 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java src/changes/changes.xml
Date Sat, 06 Oct 2012 11:41:04 GMT
Author: ggregory
Date: Sat Oct  6 11:41:04 2012
New Revision: 1395004

URL: http://svn.apache.org/viewvc?rev=1395004&view=rev
Log:
[VFS-437][FTP] StackOverFlowError getting the type of a directory with a symbolic link to
a parent directory with the same name.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java?rev=1395004&r1=1395003&r2=1395004&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
Sat Oct  6 11:41:04 2012
@@ -334,10 +334,20 @@ public class FtpFileObject extends Abstr
             }
             else if (this.fileInfo.isSymbolicLink())
             {
-                return getLinkDestination().getType();
+                FileObject linkDest = getLinkDestination();
+                // VFS-437: We need to check if the symbolic link links back to the symbolic
link itself
+                if (this.isCircular(linkDest))
+                {
+                    // If the symbolic link links back to itself, treat it as an imaginary
file to prevent following
+                    // this link. If the user tries to access the link as a file or directory,
the user will end up with
+                    // a FileSystemException warning that the file cannot be accessed. This
is to prevent the infinite
+                    // call back to doGetType() to prevent the StackOverFlow
+                    return FileType.IMAGINARY;
+                }
+                return linkDest.getType();
+
             }
         }
-
         throw new FileSystemException("vfs.provider.ftp/get-type.error", getName());
     }
 
@@ -369,10 +379,15 @@ public class FtpFileObject extends Abstr
         {
             if (this.fileInfo != null && this.fileInfo.isSymbolicLink())
             {
-                return getLinkDestination().getChildren();
+                final FileObject linkDest = getLinkDestination();
+                // VFS-437: Try to avoid a recursion loop.
+                if (this.isCircular(linkDest))
+                {
+                    return null;
+                }
+                return linkDest.getChildren();
             }
         }
-
         return null;
     }
 
@@ -399,7 +414,6 @@ public class FtpFileObject extends Abstr
             throw new FileNotFolderException(getName(), ex);
         }
 
-
         try
         {
             /* Wrap our parent implementation, noting that we're refreshing so
@@ -548,7 +562,13 @@ public class FtpFileObject extends Abstr
         {
             if (this.fileInfo.isSymbolicLink())
             {
-                return getLinkDestination().getContent().getSize();
+                final FileObject linkDest = getLinkDestination();
+                // VFS-437: Try to avoid a recursion loop.
+                if (this.isCircular(linkDest))
+                {
+                    return this.fileInfo.getSize();
+                }
+                return linkDest.getContent().getSize();
             }
             else
             {
@@ -569,19 +589,17 @@ public class FtpFileObject extends Abstr
         {
             if (this.fileInfo.isSymbolicLink())
             {
-                return getLinkDestination().getContent().getLastModifiedTime();
+                final FileObject linkDest = getLinkDestination();
+                // VFS-437: Try to avoid a recursion loop.
+                if (this.isCircular(linkDest))
+                {
+                    return getTimestamp();
+                }
+                return linkDest.getContent().getLastModifiedTime();
             }
             else
             {
-                Calendar timestamp = this.fileInfo.getTimestamp();
-                if (timestamp == null)
-                {
-                    return 0L;
-                }
-                else
-                {
-                    return timestamp.getTime().getTime();
-                }
+                return getTimestamp();
             }
         }
     }
@@ -657,6 +675,20 @@ public class FtpFileObject extends Abstr
         return relPath;
     }
 
+    private long getTimestamp()
+    {
+        Calendar timestamp = this.fileInfo.getTimestamp();
+        return timestamp == null ? 0L : timestamp.getTime().getTime();
+    }
+
+    /**
+     * This is an over simplistic implementation for VFS-437.
+     */
+    private boolean isCircular(FileObject linkDest) throws FileSystemException
+    {
+        return linkDest.getName().getPathDecoded().equals(this.getName().getPathDecoded());
+    }
+
     FtpInputStream getInputStream(long filePointer) throws IOException
     {
         final FtpClient client = getAbstractFileSystem().getClient();

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1395004&r1=1395003&r2=1395004&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Sat Oct  6 11:41:04 2012
@@ -26,6 +26,9 @@
       <action issue="VFS-439" dev="ggregory" type="fix" due-to="pensecit">
         StaticUserAuthenticator usage example wrong.
       </action>
+      <action issue="VFS-437" dev="ggregory" type="add" due-to="denniszhu, danttran, jpowang">
+        [FTP] StackOverFlowError getting the type of a directory with a symbolic link to
a parent directory with the same name.
+      </action>
       <action issue="VFS-435" dev="ggregory" type="add" due-to="george scott">
         FileSystemConfigBuilder does not use prefix for some system property lookups.
       </action>



Mime
View raw message