From 4ef448db24d0f17b2f4db358ef6896192ddbdeb2 Mon Sep 17 00:00:00 2001 From: Ulf Jaenicke-Roessler Date: Sun, 24 Apr 2022 14:27:18 +0200 Subject: [PATCH 1/2] fix request start position for chunks larger than 31952 bytes --- 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 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, }); From c61cead286f9ef14f9be634753ff0b1903f6920a Mon Sep 17 00:00:00 2001 From: Ulf Jaenicke-Roessler Date: Sun, 24 Apr 2022 16:40:42 +0200 Subject: [PATCH 2/2] add test for start position --- 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 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'); })); }));