@electerm/ssh2 1.18.2 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -115,6 +115,7 @@ const SERVER_VERSION_BUFFER = Buffer.from([
115
115
 
116
116
  const RE_OPENSSH = /^SSH-2.0-(?:OpenSSH|dropbear)/;
117
117
  const OPENSSH_MAX_PKT_LEN = 256 * 1024;
118
+ const IMPOSSIBLE_PKT_LEN = 10 * 1024 * 1024; // 10MB - if packet length is larger, it's likely garbage
118
119
 
119
120
  const bufferParser = makeBufferParser();
120
121
 
@@ -218,6 +219,17 @@ class SFTP extends EventEmitter {
218
219
  if (this._pktLen === 0)
219
220
  return doFatalSFTPError(this, 'Invalid packet length');
220
221
  if (this._pktLen > this._maxInPktLen) {
222
+ if (this._pktLen > IMPOSSIBLE_PKT_LEN) {
223
+ // Likely garbage data (e.g., text output from shell initialization)
224
+ // Reset parser state and continue
225
+ this._pktLenBytes = 0;
226
+ this._pktLen = 0;
227
+ this._pktPos = 0;
228
+ this._pktType = 0;
229
+ this._pktData = undefined;
230
+ this._pkt = undefined;
231
+ continue;
232
+ }
221
233
  const max = this._maxInPktLen;
222
234
  return doFatalSFTPError(
223
235
  this,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/ssh2",
3
- "version": "1.18.2",
3
+ "version": "1.19.0",
4
4
  "author": "Brian White <mscdex@mscdex.net>",
5
5
  "description": "SSH2 client and server modules written in pure JavaScript for node.js",
6
6
  "main": "./lib/index.js",