[
https://issues.apache.org/jira/browse/VFS-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13468268#comment-13468268
]
Dennis Zhu commented on VFS-437:
--------------------------------
Here's a proposed fix for the problem in FtpFileObject.java under the method
doGetType() inside the if block that checks for the type of this.fileInfo:
else if ( this.fileInfo.isSymbolicLink() ) {
FileObject linkDest = getLinkDestination();
// VFS-437: We need to check if the symbolic link links back to
the symbolic link itself
if ( linkDest.getName().getPathDecoded().equals(
this.getName().getPathDecoded() ) ) {
// 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();
}
The idea here is that if we detect this kind of a bad symbolic link, we return
the type of the link as a "FileType.IMAGINARY" file, which means it cannot be
accessed by any means through VFS. This will prevent the user from trying to
open the link or navigate into the link as a directory.
svndiff report and patch file comparing FtpFileObject.java is also attached
> [FTP] Program crashes when StackOverFlow Exception happens from pulling a
> softlinked directory that link to the directory that has the same name one
> level above
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: VFS-437
> URL: https://issues.apache.org/jira/browse/VFS-437
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.0
> Environment: java version "1.7.0_02"
> Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
> Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)
> Linux version 2.6.18-238.el5 ([email protected]) (gcc version
> 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu Jan 13 15:51:15 EST 2011
> Reporter: Jason
> Priority: Blocker
> Fix For: 2.1
>
> Attachments: FtpFileObject_patch, FtpFileObject_svndiff.htm
>
>
> With the setting below, StackOverFlow exceptions occur and server crashes
> set the builder.setUserDirlsRoot (opt, true)
> Attept to pull with:
> ftp://root:password@ip:/Vol1
> Vol directory has the following info
> lrwxrwxrwx 1 root root 5 Oct 5 2007 Vol1 -> /Vol1
> When it tries to look for the parent of the Vol1, it goes back to the same
> Vol1, which causes a infinite loop that eventually creates stackoverflow
> exception.
> The problem is inside the doGetType() method in FtpFileObject
> @Override
> protected FileType doGetType()
> throws Exception
> {
> // VFS-210
> synchronized (getFileSystem())
> {
> if (this.fileInfo == null)
> {
> getInfo(false);
> }
> if (this.fileInfo == UNKNOWN)
> {
> return FileType.IMAGINARY;
> }
> else if (this.fileInfo.isDirectory())
> {
> return FileType.FOLDER;
> }
> else if (this.fileInfo.isFile())
> {
> return FileType.FILE;
> }
> else if (this.fileInfo.isSymbolicLink())
> {
> return getLinkDestination().getType();
> }
> }
> throw new FileSystemException("vfs.provider.ftp/get-type.error",
> getName());
> }
> It will keep hitting the "else if (this.fileinfo.isSymbolicLink())" condition
> and the fileinfo displayed is always the Vol1 under root directory.
> Exception is shown below
> java.lang.StackOverflowError
> at org.apache.commons.net.ftp.FTPFile.isDirectory(FTPFile.java:116)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:334)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
> at
> org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetType(FtpFileObject.java:344)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira