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

[BUG] Option "Include All Subdirectories" can lead to infinite loop in File Reader with SFTP #5988

Closed
is-simon opened this issue Nov 13, 2023 · 1 comment
Labels
bug Something isn't working Fix-Commited Issue fixed and will be available in milestone Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-12023 triaged
Milestone

Comments

@is-simon
Copy link

is-simon commented Nov 13, 2023

Describe the bug
When using the "File Reader" with SFTP, using the "Include All Subdirectories" can lead to an infinite loop recursion.

I thought at first that the "Include All Subdirectories" didn't worked, but in fact it's because the connector enters an infinite loop and never comes back from its first poll.

This is because the listDirectories includes both "." and ".." directories, which should be excluded from the recursion.

Expected behavior
The "." and ".." directories should not be included in the recursion.

Actual behavior
The "." and ".." directories are included in the recursion.

Screenshots
Here's a image of my debbugger while inverstigating this problem, showing the directoryStack field.


list File Recursively infinite loop

Environment (please complete the following information):

  • Windows (sftp server unknown)
  • OpenJDK 17
  • Connect 4.4.1

Workaround(s)
I successfully fixed the problem on my local machine by changing the SftpConnection#listDirectories function from this:

@Override
public List<String> listDirectories(String fromDir) throws Exception {
    List<String> directories = new ArrayList<String>();

    cwd(fromDir);

    @SuppressWarnings("unchecked")
    Vector<ChannelSftp.LsEntry> entries = client.ls(".");

    for (Iterator<ChannelSftp.LsEntry> iter = entries.iterator(); iter.hasNext();) {
        ChannelSftp.LsEntry entry = iter.next();

        if (entry.getAttrs().isDir() || entry.getAttrs().isLink()) {
            directories.add(new SftpFileInfo(fromDir, entry).getAbsolutePath());
        }
    }

    return directories;
}

to this

@Override
public List<String> listDirectories(String fromDir) throws Exception {
    List<String> directories = new ArrayList<String>();

    cwd(fromDir);

    @SuppressWarnings("unchecked")
    Vector<ChannelSftp.LsEntry> entries = client.ls(".");

    for (Iterator<ChannelSftp.LsEntry> iter = entries.iterator(); iter.hasNext();) {
        ChannelSftp.LsEntry entry = iter.next();

        if ((entry.getAttrs().isDir() || entry.getAttrs().isLink()) && !".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())) {
            directories.add(new SftpFileInfo(fromDir, entry).getAbsolutePath());
        }
    }

    return directories;
}

But I'm not sure it is the right way to fix this soo I'll let you decide.

@is-simon is-simon added the bug Something isn't working label Nov 13, 2023
@lmillergithub lmillergithub added triaged Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-12023 labels Nov 29, 2023
@jdonextgen jdonextgen added this to the 4.5.2 milestone Aug 22, 2024
@jdonextgen
Copy link
Collaborator

Thanks @is-simon for opening this Issue. We have implemented your fix and it will go out in our 4.5.2 release.

@jdonextgen jdonextgen added the Fix-Commited Issue fixed and will be available in milestone label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fix-Commited Issue fixed and will be available in milestone Internal-Issue-Created An issue has been created in NextGen's internal issue tracker RS-12023 triaged
Projects
None yet
Development

No branches or pull requests

3 participants