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

t.c.ssh.filetransferserver.FileTransferServer.packet_READ with unhandled error #12140

Open
adiroiban opened this issue Apr 24, 2024 · 0 comments

Comments

@adiroiban
Copy link
Member

If the ID if the SSH file requested to read is not found, the current code will try to call self._ebRead(failure.Failure(KeyError()), requestId) ... but FileTransferServer._ebRead is not defined

def packet_READ(self, data):
requestId = data[:4]
data = data[4:]
handle, data = getNS(data)
(offset, length), data = struct.unpack("!QL", data[:12]), data[12:]
assert data == b"", f"still have data in READ: {data!r}"
if handle not in self.openFiles:
self._ebRead(failure.Failure(KeyError()), requestId)
else:
fileObj = self.openFiles[handle]
d = defer.maybeDeferred(fileObj.readChunk, offset, length)
d.addCallback(self._cbRead, requestId)
d.addErrback(self._ebStatus, requestId, b"read failed")
def _cbRead(self, result, requestId):
if result == b"": # Python's read will return this for EOF
raise EOFError()
self.sendPacket(FXP_DATA, requestId + NS(result))

A quick fix... not yet tested

    def packet_READ(self, data):
        requestId = data[:4]
        data = data[4:]
        handle, data = getNS(data)
        (offset, length), data = struct.unpack("!QL", data[:12]), data[12:]
        assert data == b"", f"still have data in READ: {data!r}"
        if handle not in self.openFiles:
            self._ebStatus(failure.Failure(KeyError()), requestId, b'file not found')
            return

        fileObj = self.openFiles[handle]
        d = defer.maybeDeferred(fileObj.readChunk, offset, length)
        d.addCallback(self._cbRead, requestId)
        d.addErrback(self._ebStatus, requestId, b"read failed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant