jsch icon indicating copy to clipboard operation
jsch copied to clipboard

ArrayIndexOutOfBoundsException raised on sftp downloading

Open deskangel opened this issue 1 year ago • 2 comments

I use the following codes to start sftp downloading:

        var remoteFile: InputStream? = null
            remoteFile = channel?.get(
                args["path"] as String,
                ProgressMonitor(client.id, "DownloadProgress", eventSink)
            )
            val buffer = ByteArray(4096)
            while (true) {
                val count = remoteFile.read(buffer)
                if (count == -1) {
                    break
                }
                outputStream.write(buffer, 0, count)
            }

the following exception raised sometimes:

Exception java.lang.ArrayIndexOutOfBoundsException:
  at java.lang.System.arraycopy
  at com.jcraft.jsch.ChannelSftp$2.read (ChannelSftp.java:1359)
  at java.io.InputStream.skip (InputStream.java:547)
  at com.jcraft.jsch.ChannelSftp$2.read (ChannelSftp.java:1408)
  at com.jcraft.jsch.ChannelSftp$2.read (ChannelSftp.java:1336)

The jsch version is 0.2.17.

Image

deskangel avatar Jan 22 '25 07:01 deskangel

Have you tried the latest release?

zspitzer avatar Jan 22 '25 08:01 zspitzer

I noticed that some users encountered this error, but I haven't experienced it myself.

After reviewing the release logs, I found no relevant fixes, so I reported this bug.

deskangel avatar Jan 22 '25 08:01 deskangel