From c1a69341d333f80be72d59ba4e008b8893e89045 Mon Sep 17 00:00:00 2001 From: Jamison Dance Date: Fri, 28 Oct 2011 12:54:18 -0600 Subject: [PATCH] Missing another `this` on `out`, and the bounds checking was totally borked. Bounds checking bug was preventing the size of the out array from being expanded more than once. --- lib/tar.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tar.js b/lib/tar.js index 094a50c..4e1f3df 100644 --- a/lib/tar.js +++ b/lib/tar.js @@ -80,9 +80,10 @@ this.written += headerArr.length; - // this makes sense if the input is greater than 512 bytes - if (headerArr.length + input.length > this.out.length) { - this.out = utils.extend(this.out, headerArr.length, input.length, blockSize); + // If there is not enough space in this.out, we need to expand it to + // fit the new input. + if (this.written + input.length > this.out.length) { + this.out = utils.extend(this.out, this.written, input.length, blockSize); } this.out.set(input, this.written); @@ -92,7 +93,7 @@ // make sure there's at least 2 empty records worth of extra space if (this.out.length - this.written < recordSize * 2) { - this.out = utils.extend(out, this.written, recordSize * 2, blockSize); + this.out = utils.extend(this.out, this.written, recordSize * 2, blockSize); } if (typeof callback === 'function') {