From 8214df504f39502434c1cdde634674723880820b Mon Sep 17 00:00:00 2001 From: Petter Date: Thu, 13 Apr 2023 21:16:06 -0700 Subject: [PATCH] Fix a bug where errors could leak on extremely large stream chunks --- packages/csv-stringify/dist/cjs/index.cjs | 11 ++++++++++- packages/csv-stringify/dist/esm/index.js | 11 ++++++++++- packages/csv-stringify/dist/iife/index.js | 11 ++++++++++- packages/csv-stringify/dist/umd/index.js | 11 ++++++++++- packages/csv-stringify/lib/index.js | 11 ++++++++++- packages/csv/dist/cjs/index.cjs | 13 +++++++++++-- packages/csv/dist/cjs/sync.cjs | 2 +- packages/csv/dist/esm/index.js | 13 +++++++++++-- packages/csv/dist/esm/sync.js | 2 +- packages/csv/dist/iife/index.js | 13 +++++++++++-- packages/csv/dist/iife/sync.js | 2 +- packages/csv/dist/umd/index.js | 13 +++++++++++-- packages/csv/dist/umd/sync.js | 2 +- 13 files changed, 98 insertions(+), 17 deletions(-) diff --git a/packages/csv-stringify/dist/cjs/index.cjs b/packages/csv-stringify/dist/cjs/index.cjs index 4963a2c10..663671cdd 100644 --- a/packages/csv-stringify/dist/cjs/index.cjs +++ b/packages/csv-stringify/dist/cjs/index.cjs @@ -627,7 +627,16 @@ const stringify = function(){ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv-stringify/dist/esm/index.js b/packages/csv-stringify/dist/esm/index.js index 2764244df..894120964 100644 --- a/packages/csv-stringify/dist/esm/index.js +++ b/packages/csv-stringify/dist/esm/index.js @@ -5685,7 +5685,16 @@ const stringify = function(){ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv-stringify/dist/iife/index.js b/packages/csv-stringify/dist/iife/index.js index ff9f636ff..bd39e58e4 100644 --- a/packages/csv-stringify/dist/iife/index.js +++ b/packages/csv-stringify/dist/iife/index.js @@ -5688,7 +5688,16 @@ var csv_stringify = (function (exports) { callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv-stringify/dist/umd/index.js b/packages/csv-stringify/dist/umd/index.js index c112dd9f9..61840d98c 100644 --- a/packages/csv-stringify/dist/umd/index.js +++ b/packages/csv-stringify/dist/umd/index.js @@ -5691,7 +5691,16 @@ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv-stringify/lib/index.js b/packages/csv-stringify/lib/index.js index d6546a5f4..949e95490 100644 --- a/packages/csv-stringify/lib/index.js +++ b/packages/csv-stringify/lib/index.js @@ -88,7 +88,16 @@ const stringify = function(){ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv/dist/cjs/index.cjs b/packages/csv/dist/cjs/index.cjs index bfae70156..43f015ed2 100644 --- a/packages/csv/dist/cjs/index.cjs +++ b/packages/csv/dist/cjs/index.cjs @@ -267,7 +267,7 @@ let CsvError$1 = class CsvError extends Error { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ @@ -2423,7 +2423,16 @@ const stringify = function(){ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv/dist/cjs/sync.cjs b/packages/csv/dist/cjs/sync.cjs index a753325c9..ab358cf48 100644 --- a/packages/csv/dist/cjs/sync.cjs +++ b/packages/csv/dist/cjs/sync.cjs @@ -260,7 +260,7 @@ let CsvError$1 = class CsvError extends Error { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ diff --git a/packages/csv/dist/esm/index.js b/packages/csv/dist/esm/index.js index dea91f9fd..7c3332c02 100644 --- a/packages/csv/dist/esm/index.js +++ b/packages/csv/dist/esm/index.js @@ -5394,7 +5394,7 @@ let CsvError$1 = class CsvError extends Error { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ @@ -7550,7 +7550,16 @@ const stringify = function(){ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv/dist/esm/sync.js b/packages/csv/dist/esm/sync.js index 661141267..f36c4bf1b 100644 --- a/packages/csv/dist/esm/sync.js +++ b/packages/csv/dist/esm/sync.js @@ -5387,7 +5387,7 @@ let CsvError$1 = class CsvError extends Error { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ diff --git a/packages/csv/dist/iife/index.js b/packages/csv/dist/iife/index.js index cbbb31dc7..34cc709a8 100644 --- a/packages/csv/dist/iife/index.js +++ b/packages/csv/dist/iife/index.js @@ -5397,7 +5397,7 @@ var csv = (function (exports) { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ @@ -7553,7 +7553,16 @@ var csv = (function (exports) { callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv/dist/iife/sync.js b/packages/csv/dist/iife/sync.js index 9e2c4dd6c..5718c67fc 100644 --- a/packages/csv/dist/iife/sync.js +++ b/packages/csv/dist/iife/sync.js @@ -5390,7 +5390,7 @@ var csv_sync = (function (exports) { if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ diff --git a/packages/csv/dist/umd/index.js b/packages/csv/dist/umd/index.js index ac33f79b2..6f3153011 100644 --- a/packages/csv/dist/umd/index.js +++ b/packages/csv/dist/umd/index.js @@ -5400,7 +5400,7 @@ if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){ @@ -7556,7 +7556,16 @@ callback(err); }); stringifier.on('end', function(){ - callback(undefined, chunks.join('')); + let result; + try { + result = chunks.join(''); + } catch (err) { + // This can happen if the result is extremely long; it may throw + // "Cannot create a string longer than 0x1fffffe8 characters" + callback(err); + return; + } + callback(undefined, result); }); } if(data !== undefined){ diff --git a/packages/csv/dist/umd/sync.js b/packages/csv/dist/umd/sync.js index 6dc300fc4..51b9584d4 100644 --- a/packages/csv/dist/umd/sync.js +++ b/packages/csv/dist/umd/sync.js @@ -5393,7 +5393,7 @@ if(Array.isArray(message)) message = message.join(' ').trim(); super(message); if(Error.captureStackTrace !== undefined){ - Error.captureStackTrace(this, CsvError$1); + Error.captureStackTrace(this, CsvError); } this.code = code; for(const context of contexts){