From 5c4845814ab2da53b30144d8545a7f8b4ef6e66f Mon Sep 17 00:00:00 2001 From: Ulf Jaenicke-Roessler Date: Fri, 3 Apr 2026 22:11:34 +0200 Subject: [PATCH 1/2] test: test case showing bug handing wrong position over to callback --- test/test-sftp.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test-sftp.js b/test/test-sftp.js index 595e5091..2f42e92b 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) => { + const 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'); })); })); From fad473ba4173a0c6468e864c85e6fa16fb54c9f2 Mon Sep 17 00:00:00 2001 From: Ulf Jaenicke-Roessler Date: Fri, 3 Apr 2026 22:13:03 +0200 Subject: [PATCH 2/2] fix: give actual base position to callback --- lib/protocol/SFTP.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protocol/SFTP.js b/lib/protocol/SFTP.js index 9f33c021..19fcc8c4 100644 --- a/lib/protocol/SFTP.js +++ b/lib/protocol/SFTP.js @@ -2136,6 +2136,7 @@ function read_(self, handle, buf, off, len, position, cb, req_) { const req = (req_ || { nb: 0, position, + origPosition: position, off, origOff: off, len: undefined, @@ -2162,7 +2163,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, });