From ecde48e78faf2ab3b6cfc34e36a46c6621e07b34 Mon Sep 17 00:00:00 2001 From: Erik Moura Date: Tue, 26 Sep 2023 21:29:55 -0300 Subject: [PATCH] fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly (#253) * fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly * fix: directory name case * fix: remove trailing line endings --- lib/filesystem.js | 10 +++++----- test/api-spec.js | 8 ++++++++ test/expected/packthis-object-prototype.asar | Bin 0 -> 3099 bytes test/input/packthis-object-prototype/__proto__ | 1 + .../constructor/__proto__ | 1 + .../constructor/constructor | 1 + .../packthis-object-prototype/constructor/file1 | 1 + test/input/packthis-object-prototype/file1 | 1 + test/input/packthis-object-prototype/file2 | 1 + .../constructor/constructor/__proto__/__proto__ | 1 + .../constructor/constructor/__proto__/file1 | 1 + .../folder1/constructor/constructor/constructor | 1 + .../folder1/constructor/constructor/file1 | 1 + .../packthis-object-prototype/folder1/file1 | 1 + 14 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/expected/packthis-object-prototype.asar create mode 100644 test/input/packthis-object-prototype/__proto__ create mode 100644 test/input/packthis-object-prototype/constructor/__proto__ create mode 100644 test/input/packthis-object-prototype/constructor/constructor create mode 100644 test/input/packthis-object-prototype/constructor/file1 create mode 100644 test/input/packthis-object-prototype/file1 create mode 100644 test/input/packthis-object-prototype/file2 create mode 100644 test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ create mode 100644 test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 create mode 100644 test/input/packthis-object-prototype/folder1/constructor/constructor/constructor create mode 100644 test/input/packthis-object-prototype/folder1/constructor/constructor/file1 create mode 100644 test/input/packthis-object-prototype/folder1/file1 diff --git a/lib/filesystem.js b/lib/filesystem.js index 908b0dd..ce10245 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -14,7 +14,7 @@ const pipeline = promisify(stream.pipeline) class Filesystem { constructor (src) { this.src = path.resolve(src) - this.header = { files: {} } + this.header = { files: Object.create(null) } this.offset = BigInt(0) } @@ -24,7 +24,7 @@ class Filesystem { for (const dir of dirs) { if (dir !== '.') { if (!json.files[dir]) { - json.files[dir] = { files: {} } + json.files[dir] = { files: Object.create(null) } } json = json.files[dir] } @@ -38,10 +38,10 @@ class Filesystem { const name = path.basename(p) const node = this.searchNodeFromDirectory(path.dirname(p)) if (node.files == null) { - node.files = {} + node.files = Object.create(null) } if (node.files[name] == null) { - node.files[name] = {} + node.files[name] = Object.create(null) } return node.files[name] } @@ -51,7 +51,7 @@ class Filesystem { if (shouldUnpack) { node.unpacked = shouldUnpack } - node.files = node.files || {} + node.files = node.files || Object.create(null) return node.files } diff --git a/test/api-spec.js b/test/api-spec.js index 3d4f5ce..d50323d 100644 --- a/test/api-spec.js +++ b/test/api-spec.js @@ -94,4 +94,12 @@ describe('api', function () { const expected = await fs.readFile('test/input/packthis-unicode-path/dir1/女の子.txt', 'utf8') return compFileLists(actual, expected) }) + it('should create files/directories whose names are properties of Object.prototype', async () => { + await asar.createPackage('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype.asar') + return compFiles('tmp/packthis-object-prototype.asar', 'test/expected/packthis-object-prototype.asar') + }) + it('should extract files/directories whose names are properties of Object.prototype', () => { + asar.extractAll('test/expected/packthis-object-prototype.asar', 'tmp/packthis-object-prototype/') + return compDirs('test/input/packthis-object-prototype/', 'tmp/packthis-object-prototype') + }) }) diff --git a/test/expected/packthis-object-prototype.asar b/test/expected/packthis-object-prototype.asar new file mode 100644 index 0000000000000000000000000000000000000000..a7bad8cc1ffe0c9637d8e8408070692695e32b46 GIT binary patch literal 3099 zcmbtW!EPHj5cMIa<}dbaz~l^v9Qu}9?>QEQF&uJYBW_ek>Y)wt;k|Vv1@gL3vKAJC zR$T6iZ{NJ(d;9L@=H}gdKlu0GUv6%`PWJRXcGLaW>EYqe?PkAucsQKwp8grreZ8GF zX1lSU?x!%_PETL<TW1I0!a#8+z18~yz8_!ueHgdu&O^N0OyJ;3kZzTHl` z`Lf$@|I+MtfrBO6V?)fFb=Vz*)Tv296Q@+qiIbPTGlLM z)P}-*sQb@ru^Qk~Elv#pIAe`hwE!tcRW6oBso8if%{;S#zHm##>+QUy!uPyz^AZxILiM}oJ4 zNF`yv(6NS;q=GFfyc*!dck|rG_Sn>CNBfb}{b>GG7@SvmHG6Uhn)~9>tlk_FnnDO! zqA+w!Y~Vj^)GUV4QwDYC&=$@8jk9ov$PLPfXh7y}xmeEC0O$6ZIYgQ}L_9X}n;DmG ztx+g8Fjw-{5ep?}5(T8;(@fNAB#7X3&<0dlf_tM{%pRbNj8_9V;|sxfk~+=9AQrx6 z>jVt}dkQX_I=P{}b*MZ55shi27JHS!sOqz&B#pJSiVVn}5owY6YJf{x<6LWigJHc{ zYY)64EC>PIB3NZ04)5{Ov1nv6e+MYQO?+Itq-KQXUIKhb!mylws{xK$UkHRa*BR(4 zok@DOMkFAud#HJoTcs=#0i1mgL;NLBJuZ@t=$oEHD8rL77vBS8Eb6=(;5%!71wOmk u%mnW)PR?$a4eyRYdOm=ieD`jC%Y1xZ`UT|ee>uS{Ak5H~R(`eK@#H@^PN