diff --git a/lib/protocol/SFTP.js b/lib/protocol/SFTP.js index a7fc4f90..9ea3ee0c 100644 --- a/lib/protocol/SFTP.js +++ b/lib/protocol/SFTP.js @@ -1986,6 +1986,7 @@ function read_(self, handle, buf, off, len, position, cb, req_) { const req = (req_ || { nb: 0, position, + origPosition: position, off, origOff: off, len: undefined, @@ -2012,7 +2013,7 @@ function read_(self, handle, buf, off, len, position, cb, req_) { data = buf; else data = bufferSlice(buf, req.origOff, req.origOff + req.nb + nb); - cb(undefined, req.nb + nb, data, req.position); + cb(undefined, req.nb + nb, data, req.origPosition); }, buffer: undefined, }); diff --git a/test/test-sftp.js b/test/test-sftp.js index 1bda7668..65e33479 100644 --- a/test/test-sftp.js +++ b/test/test-sftp.js @@ -105,10 +105,12 @@ setup('read (overflow)', mustCall((client, server) => { if (reqs === 3) server.end(); }, 3)); - client.read(handle_, buf, 0, buf.length, 0, mustCall((err, nb) => { + let reqPos = 0 + client.read(handle_, buf, 0, buf.length, reqPos, mustCall((err, nb, retBuf, retPos) => { assert(!err, `Unexpected read() error: ${err}`); assert.deepStrictEqual(buf, expected); assert.strictEqual(nb, buf.length, 'read nb mismatch'); + assert.strictEqual(reqPos, retPos, 'read ressource position does not match request'); })); }));