From 9a3fc9ebdb00a71977306896bec48e0fc8969859 Mon Sep 17 00:00:00 2001 From: Erik Moura Date: Tue, 6 Dec 2022 11:03:36 -0300 Subject: [PATCH 1/3] fix: ensure that files/folders whose names are properties of Object.prototype are packaged/extracted correctly --- lib/filesystem.js | 10 +++++----- test/api-spec.js | 8 ++++++++ test/expected/packthis-object-prototype.asar | Bin 0 -> 3110 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..e68ba725888b78cc8bfabec1f83b798db2b58d5a GIT binary patch literal 3110 zcmbtWO>Y}F5Y-_k=U?b-Ae;{lN#AXVzAlzF^y4g(>js*!bFC*8}|a?c43v zc3)oh&wtr|_dGHBSuGG}wSeo2f$W77TWPmMU)Dt z9hk6E@tPJ1uLc-|C)xjxvdkDKzNW>ac@`r{PgL7bbO!0cmBZlgJ$k7bLMy;rD5O{d z)mnlewUR2dyvTSpz^TRfy~T6B`Kp~PY4{YU?5eE>;;OL}X0IisG$?T~71ca8ZsM3z zC-G|4y-MsU_#)rc07t&Nr{>QGQJ*aBM^^Wv@v}HMt#UScbci@N#ymOqn>S2$?g33K zry_M!Hh_U7M#QRN#KHJcgbFUbacULwP#Oj534_XVN~{Jr$!F#eJa-77NyJw$ri=`! zRHd8^hXG22DpQ4je)3xl@XC5~^0J$m w2Y$FbI-7Ae`;eqJ->-PnkKX%X_Qu)$Y5f_}+uwObTELiLFMiMYipQt_0GC*vQ~&?~ literal 0 HcmV?d00001 diff --git a/test/input/packThis-object-prototype/__proto__ b/test/input/packThis-object-prototype/__proto__ new file mode 100644 index 0000000..7d590c9 --- /dev/null +++ b/test/input/packThis-object-prototype/__proto__ @@ -0,0 +1 @@ +__proto__ diff --git a/test/input/packThis-object-prototype/constructor/__proto__ b/test/input/packThis-object-prototype/constructor/__proto__ new file mode 100644 index 0000000..94a8b49 --- /dev/null +++ b/test/input/packThis-object-prototype/constructor/__proto__ @@ -0,0 +1 @@ +constructor/__proto__ diff --git a/test/input/packThis-object-prototype/constructor/constructor b/test/input/packThis-object-prototype/constructor/constructor new file mode 100644 index 0000000..1987daa --- /dev/null +++ b/test/input/packThis-object-prototype/constructor/constructor @@ -0,0 +1 @@ +constructor/constructor diff --git a/test/input/packThis-object-prototype/constructor/file1 b/test/input/packThis-object-prototype/constructor/file1 new file mode 100644 index 0000000..b4fec81 --- /dev/null +++ b/test/input/packThis-object-prototype/constructor/file1 @@ -0,0 +1 @@ +constructor/file1 diff --git a/test/input/packThis-object-prototype/file1 b/test/input/packThis-object-prototype/file1 new file mode 100644 index 0000000..e212970 --- /dev/null +++ b/test/input/packThis-object-prototype/file1 @@ -0,0 +1 @@ +file1 diff --git a/test/input/packThis-object-prototype/file2 b/test/input/packThis-object-prototype/file2 new file mode 100644 index 0000000..6c493ff --- /dev/null +++ b/test/input/packThis-object-prototype/file2 @@ -0,0 +1 @@ +file2 diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ b/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ new file mode 100644 index 0000000..fb09d30 --- /dev/null +++ b/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ @@ -0,0 +1 @@ +folder1/constructor/constructor/__proto__/__proto__ diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/file1 b/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/file1 new file mode 100644 index 0000000..9ff42d5 --- /dev/null +++ b/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/file1 @@ -0,0 +1 @@ +folder1/constructor/constructor/__proto__/file1 diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/constructor b/test/input/packThis-object-prototype/folder1/constructor/constructor/constructor new file mode 100644 index 0000000..07e65b9 --- /dev/null +++ b/test/input/packThis-object-prototype/folder1/constructor/constructor/constructor @@ -0,0 +1 @@ +folder1/constructor/constructor/constructor diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/file1 b/test/input/packThis-object-prototype/folder1/constructor/constructor/file1 new file mode 100644 index 0000000..069d699 --- /dev/null +++ b/test/input/packThis-object-prototype/folder1/constructor/constructor/file1 @@ -0,0 +1 @@ +folder1/constructor/constructor/file1 diff --git a/test/input/packThis-object-prototype/folder1/file1 b/test/input/packThis-object-prototype/folder1/file1 new file mode 100644 index 0000000..800b122 --- /dev/null +++ b/test/input/packThis-object-prototype/folder1/file1 @@ -0,0 +1 @@ +folder1/file1 From 3cc3b6b762ebdb1fb7e6cb6229759c7bed543a99 Mon Sep 17 00:00:00 2001 From: Erik Moura Date: Tue, 6 Dec 2022 12:05:32 -0300 Subject: [PATCH 2/3] fix: directory name case --- .../__proto__ | 0 .../constructor/__proto__ | 0 .../constructor/constructor | 0 .../constructor/file1 | 0 .../file1 | 0 .../file2 | 0 .../folder1/constructor/constructor/__proto__/__proto__ | 0 .../folder1/constructor/constructor/__proto__/file1 | 0 .../folder1/constructor/constructor/constructor | 0 .../folder1/constructor/constructor/file1 | 0 .../folder1/file1 | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename test/input/{packThis-object-prototype => packthis-object-prototype}/__proto__ (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/constructor/__proto__ (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/constructor/constructor (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/constructor/file1 (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/file1 (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/file2 (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/folder1/constructor/constructor/__proto__/__proto__ (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/folder1/constructor/constructor/__proto__/file1 (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/folder1/constructor/constructor/constructor (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/folder1/constructor/constructor/file1 (100%) rename test/input/{packThis-object-prototype => packthis-object-prototype}/folder1/file1 (100%) diff --git a/test/input/packThis-object-prototype/__proto__ b/test/input/packthis-object-prototype/__proto__ similarity index 100% rename from test/input/packThis-object-prototype/__proto__ rename to test/input/packthis-object-prototype/__proto__ diff --git a/test/input/packThis-object-prototype/constructor/__proto__ b/test/input/packthis-object-prototype/constructor/__proto__ similarity index 100% rename from test/input/packThis-object-prototype/constructor/__proto__ rename to test/input/packthis-object-prototype/constructor/__proto__ diff --git a/test/input/packThis-object-prototype/constructor/constructor b/test/input/packthis-object-prototype/constructor/constructor similarity index 100% rename from test/input/packThis-object-prototype/constructor/constructor rename to test/input/packthis-object-prototype/constructor/constructor diff --git a/test/input/packThis-object-prototype/constructor/file1 b/test/input/packthis-object-prototype/constructor/file1 similarity index 100% rename from test/input/packThis-object-prototype/constructor/file1 rename to test/input/packthis-object-prototype/constructor/file1 diff --git a/test/input/packThis-object-prototype/file1 b/test/input/packthis-object-prototype/file1 similarity index 100% rename from test/input/packThis-object-prototype/file1 rename to test/input/packthis-object-prototype/file1 diff --git a/test/input/packThis-object-prototype/file2 b/test/input/packthis-object-prototype/file2 similarity index 100% rename from test/input/packThis-object-prototype/file2 rename to test/input/packthis-object-prototype/file2 diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ similarity index 100% rename from test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ rename to test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 similarity index 100% rename from test/input/packThis-object-prototype/folder1/constructor/constructor/__proto__/file1 rename to test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/constructor b/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor similarity index 100% rename from test/input/packThis-object-prototype/folder1/constructor/constructor/constructor rename to test/input/packthis-object-prototype/folder1/constructor/constructor/constructor diff --git a/test/input/packThis-object-prototype/folder1/constructor/constructor/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 similarity index 100% rename from test/input/packThis-object-prototype/folder1/constructor/constructor/file1 rename to test/input/packthis-object-prototype/folder1/constructor/constructor/file1 diff --git a/test/input/packThis-object-prototype/folder1/file1 b/test/input/packthis-object-prototype/folder1/file1 similarity index 100% rename from test/input/packThis-object-prototype/folder1/file1 rename to test/input/packthis-object-prototype/folder1/file1 From 63f6794c003b9f0fa6f45cd8f2635239a77af368 Mon Sep 17 00:00:00 2001 From: Erik Moura Date: Tue, 6 Dec 2022 12:22:29 -0300 Subject: [PATCH 3/3] fix: remove trailing line endings --- test/expected/packthis-object-prototype.asar | Bin 3110 -> 3099 bytes .../input/packthis-object-prototype/__proto__ | 2 +- .../constructor/__proto__ | 2 +- .../constructor/constructor | 2 +- .../constructor/file1 | 2 +- test/input/packthis-object-prototype/file1 | 2 +- test/input/packthis-object-prototype/file2 | 2 +- .../constructor/__proto__/__proto__ | 2 +- .../constructor/constructor/__proto__/file1 | 2 +- .../constructor/constructor/constructor | 2 +- .../folder1/constructor/constructor/file1 | 2 +- .../packthis-object-prototype/folder1/file1 | 2 +- 12 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/expected/packthis-object-prototype.asar b/test/expected/packthis-object-prototype.asar index e68ba725888b78cc8bfabec1f83b798db2b58d5a..a7bad8cc1ffe0c9637d8e8408070692695e32b46 100644 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@^PNY}F5Y-_k=U?b-Ae;{lN#AXVzAlzF^y4g(>js*!bFC*8}|a?c43v zc3)oh&wtr|_dGHBSuGG}wSeo2f$W77TWPmMU)Dt z9hk6E@tPJ1uLc-|C)xjxvdkDKzNW>ac@`r{PgL7bbO!0cmBZlgJ$k7bLMy;rD5O{d z)mnlewUR2dyvTSpz^TRfy~T6B`Kp~PY4{YU?5eE>;;OL}X0IisG$?T~71ca8ZsM3z zC-G|4y-MsU_#)rc07t&Nr{>QGQJ*aBM^^Wv@v}HMt#UScbci@N#ymOqn>S2$?g33K zry_M!Hh_U7M#QRN#KHJcgbFUbacULwP#Oj534_XVN~{Jr$!F#eJa-77NyJw$ri=`! zRHd8^hXG22DpQ4je)3xl@XC5~^0J$m w2Y$FbI-7Ae`;eqJ->-PnkKX%X_Qu)$Y5f_}+uwObTELiLFMiMYipQt_0GC*vQ~&?~ diff --git a/test/input/packthis-object-prototype/__proto__ b/test/input/packthis-object-prototype/__proto__ index 7d590c9..84437e7 100644 --- a/test/input/packthis-object-prototype/__proto__ +++ b/test/input/packthis-object-prototype/__proto__ @@ -1 +1 @@ -__proto__ +__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/__proto__ b/test/input/packthis-object-prototype/constructor/__proto__ index 94a8b49..bd07bcf 100644 --- a/test/input/packthis-object-prototype/constructor/__proto__ +++ b/test/input/packthis-object-prototype/constructor/__proto__ @@ -1 +1 @@ -constructor/__proto__ +constructor/__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/constructor b/test/input/packthis-object-prototype/constructor/constructor index 1987daa..4c4cc0c 100644 --- a/test/input/packthis-object-prototype/constructor/constructor +++ b/test/input/packthis-object-prototype/constructor/constructor @@ -1 +1 @@ -constructor/constructor +constructor/constructor \ No newline at end of file diff --git a/test/input/packthis-object-prototype/constructor/file1 b/test/input/packthis-object-prototype/constructor/file1 index b4fec81..7d188b0 100644 --- a/test/input/packthis-object-prototype/constructor/file1 +++ b/test/input/packthis-object-prototype/constructor/file1 @@ -1 +1 @@ -constructor/file1 +constructor/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/file1 b/test/input/packthis-object-prototype/file1 index e212970..08219db 100644 --- a/test/input/packthis-object-prototype/file1 +++ b/test/input/packthis-object-prototype/file1 @@ -1 +1 @@ -file1 +file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/file2 b/test/input/packthis-object-prototype/file2 index 6c493ff..30d67d4 100644 --- a/test/input/packthis-object-prototype/file2 +++ b/test/input/packthis-object-prototype/file2 @@ -1 +1 @@ -file2 +file2 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ index fb09d30..1cd727b 100644 --- a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/__proto__ @@ -1 +1 @@ -folder1/constructor/constructor/__proto__/__proto__ +folder1/constructor/constructor/__proto__/__proto__ \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 index 9ff42d5..c9cb751 100644 --- a/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/__proto__/file1 @@ -1 +1 @@ -folder1/constructor/constructor/__proto__/file1 +folder1/constructor/constructor/__proto__/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor b/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor index 07e65b9..757c3ea 100644 --- a/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/constructor @@ -1 +1 @@ -folder1/constructor/constructor/constructor +folder1/constructor/constructor/constructor \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 b/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 index 069d699..3b0d002 100644 --- a/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 +++ b/test/input/packthis-object-prototype/folder1/constructor/constructor/file1 @@ -1 +1 @@ -folder1/constructor/constructor/file1 +folder1/constructor/constructor/file1 \ No newline at end of file diff --git a/test/input/packthis-object-prototype/folder1/file1 b/test/input/packthis-object-prototype/folder1/file1 index 800b122..b3ce553 100644 --- a/test/input/packthis-object-prototype/folder1/file1 +++ b/test/input/packthis-object-prototype/folder1/file1 @@ -1 +1 @@ -folder1/file1 +folder1/file1 \ No newline at end of file