From 39e14d70eecbfe8addc5c0207d04af70b6d5ccb6 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 13 Oct 2020 16:24:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=B0=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D0=BF=D0=B0=D0=BA=D0=BE=D0=B2=D0=BA=D0=B8=20Zip-?= =?UTF-8?q?=D0=B0=D1=80=D1=85=D0=B8=D0=B2=D0=BE=D0=B2=20=D1=81=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=BE=D1=85=D0=B8=D0=BC=D0=B8=20=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/FileDecompressor.js | 9 +++++++-- server/core/Zip/node_stream_zip.js | 2 +- server/core/utils.js | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/core/FileDecompressor.js b/server/core/FileDecompressor.js index 382d4105..ab2e58b2 100644 --- a/server/core/FileDecompressor.js +++ b/server/core/FileDecompressor.js @@ -119,14 +119,19 @@ class FileDecompressor { try { return await zip.unpack(filename, outputDir, { limitFileSize: this.limitFileSize, - limitFileCount: 1000 - }); + limitFileCount: 1000, + decodeEntryNameCallback: (nameRaw) => { + return utils.bufferRemoveZeroes(nameRaw); + } + } +); } catch (e) { fs.emptyDir(outputDir); return await zip.unpack(filename, outputDir, { limitFileSize: this.limitFileSize, limitFileCount: 1000, decodeEntryNameCallback: (nameRaw) => { + nameRaw = utils.bufferRemoveZeroes(nameRaw); const enc = textUtils.getEncodingLite(nameRaw); if (enc.indexOf('ISO-8859') < 0) { return iconv.decode(nameRaw, enc); diff --git a/server/core/Zip/node_stream_zip.js b/server/core/Zip/node_stream_zip.js index d60cc996..81a40fc2 100644 --- a/server/core/Zip/node_stream_zip.js +++ b/server/core/Zip/node_stream_zip.js @@ -766,7 +766,7 @@ ZipEntry.prototype.readDataHeader = function(data) { }; ZipEntry.prototype.read = function(data, offset) { - this.nameRaw = data.slice(offset, offset += this.fnameLen); + this.nameRaw = Buffer.from(data.slice(offset, offset += this.fnameLen)); this.name = this.nameRaw.toString(); var lastChar = data[offset - 1]; this.isDirectory = (lastChar == 47) || (lastChar == 92); diff --git a/server/core/utils.js b/server/core/utils.js index 53f7a2b3..f5190ded 100644 --- a/server/core/utils.js +++ b/server/core/utils.js @@ -14,6 +14,14 @@ function fromBase36(data) { return bs36.decode(data); } +function bufferRemoveZeroes(buf) { + const i = buf.indexOf(0); + if (i >= 0) { + return buf.slice(0, i); + } + return buf; +} + function getFileHash(filename, hashName, enc) { return new Promise((resolve, reject) => { const hash = crypto.createHash(hashName); @@ -86,6 +94,7 @@ function spawnProcess(cmd, opts) { module.exports = { toBase36, fromBase36, + bufferRemoveZeroes, getFileHash, sleep, randomHexString,