From 120de738662fb1dbfe108adc76d47fce8ce916d7 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 17 Jun 2025 10:01:32 -0700 Subject: [PATCH 1/5] JS FS: Don't return ELOOP on a path with a large number of ..'s Decrement nlinks before doing `continue linkloop;` due to a .. at a file system loop. We're not actually traversing a symlink here. --- src/lib/libfs.js | 3 +++ test/test_other.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/libfs.js b/src/lib/libfs.js index d7d628ce70d8f..c2c6908797c8f 100644 --- a/src/lib/libfs.js +++ b/src/lib/libfs.js @@ -199,6 +199,9 @@ FS.staticInit();`; current_path = PATH.dirname(current_path); if (FS.isRoot(current)) { path = current_path + '/' + parts.slice(i + 1).join('/'); + // We're making progress here, don't let many consecutive ..'s + // lead to ELOOP + nlinks --; continue linkloop; } else { current = current.parent; diff --git a/test/test_other.py b/test/test_other.py index 57ceb9f093f16..2c08f770aa484 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -16084,3 +16084,19 @@ def test_em_js_bool_macro_expansion(self): } ''') self.do_runf('main.c') + + def test_stat_many_dotdot(self): + path = "/".join([".."] * 75) + create_file('main.c', ''' + #include + #include + #include + + int main() { + struct stat path_stat; + ''' + f'return stat("{path}", &path_stat);' + ''' + } + ''') + self.do_runf('main.c') From 6f67b047052438fe0b25df956dcf95cab22ca96e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 17 Jun 2025 10:12:58 -0700 Subject: [PATCH 2/5] Apply sbc100's review comments --- src/lib/libfs.js | 2 +- test/test_other.py | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/lib/libfs.js b/src/lib/libfs.js index c2c6908797c8f..ae34e0529d31d 100644 --- a/src/lib/libfs.js +++ b/src/lib/libfs.js @@ -201,7 +201,7 @@ FS.staticInit();`; path = current_path + '/' + parts.slice(i + 1).join('/'); // We're making progress here, don't let many consecutive ..'s // lead to ELOOP - nlinks --; + nlinks--; continue linkloop; } else { current = current.parent; diff --git a/test/test_other.py b/test/test_other.py index 2c08f770aa484..0bd1e64c17667 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -6009,6 +6009,21 @@ def test_symlink_silly(self): self.assertContained(r'ok', self.run_js('a.out.js', args=['123', 'abc'])) self.assertContained(r'Failed to symlink paths: abc, ; errno=44', self.run_js('a.out.js', args=['abc', ''])) + def test_stat_many_dotdot(self): + path = "/".join([".."] * 75) + create_file('main.c', ''' + #include + #include + #include + + int main() { + struct stat path_stat; + return stat("%s", &path_stat); + } + ''' % path) + self.do_runf('main.c') + + def test_rename_silly(self): create_file('src.c', r''' #include @@ -16084,19 +16099,3 @@ def test_em_js_bool_macro_expansion(self): } ''') self.do_runf('main.c') - - def test_stat_many_dotdot(self): - path = "/".join([".."] * 75) - create_file('main.c', ''' - #include - #include - #include - - int main() { - struct stat path_stat; - ''' - f'return stat("{path}", &path_stat);' - ''' - } - ''') - self.do_runf('main.c') From ac1aa487d29d1214a6ad2e421851e1bced8e2859 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 17 Jun 2025 10:50:05 -0700 Subject: [PATCH 3/5] with_all_fs --- test/test_other.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_other.py b/test/test_other.py index 0bd1e64c17667..67935f83c8e5e 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -6009,6 +6009,7 @@ def test_symlink_silly(self): self.assertContained(r'ok', self.run_js('a.out.js', args=['123', 'abc'])) self.assertContained(r'Failed to symlink paths: abc, ; errno=44', self.run_js('a.out.js', args=['abc', ''])) + @with_all_fs def test_stat_many_dotdot(self): path = "/".join([".."] * 75) create_file('main.c', ''' From dedcb35bc407a61d08171b0ed57d836d6b1b5f7b Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 17 Jun 2025 11:14:36 -0700 Subject: [PATCH 4/5] Fix ruff --- test/test_other.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_other.py b/test/test_other.py index 67935f83c8e5e..593359044c788 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -6024,7 +6024,6 @@ def test_stat_many_dotdot(self): ''' % path) self.do_runf('main.c') - def test_rename_silly(self): create_file('src.c', r''' #include From fc85fd2c302e6ef8a1871c9c0924309210dc64a5 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 17 Jun 2025 12:12:00 -0700 Subject: [PATCH 5/5] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (20) test expectation files were updated by running the tests with `--rebaseline`: ``` test/other/codesize/test_codesize_cxx_ctors1.gzsize updated test/other/codesize/test_codesize_cxx_ctors1.jssize updated test/other/codesize/test_codesize_cxx_ctors2.gzsize updated test/other/codesize/test_codesize_cxx_ctors2.jssize updated test/other/codesize/test_codesize_cxx_except.gzsize updated test/other/codesize/test_codesize_cxx_except.jssize updated test/other/codesize/test_codesize_cxx_except_wasm.gzsize updated test/other/codesize/test_codesize_cxx_except_wasm.jssize updated test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize updated test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize updated test/other/codesize/test_codesize_cxx_lto.gzsize updated test/other/codesize/test_codesize_cxx_lto.jssize updated test/other/codesize/test_codesize_cxx_mangle.gzsize updated test/other/codesize/test_codesize_cxx_mangle.jssize updated test/other/codesize/test_codesize_cxx_noexcept.gzsize updated test/other/codesize/test_codesize_cxx_noexcept.jssize updated test/other/codesize/test_codesize_files_js_fs.gzsize updated test/other/codesize/test_codesize_files_js_fs.jssize updated test/other/codesize/test_codesize_hello_dylink.gzsize updated test/other/codesize/test_codesize_hello_dylink.jssize updated ``` --- test/other/codesize/test_codesize_cxx_ctors1.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors1.jssize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.jssize | 2 +- test/other/codesize/test_codesize_cxx_except.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except.jssize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm.jssize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize | 2 +- test/other/codesize/test_codesize_cxx_lto.gzsize | 2 +- test/other/codesize/test_codesize_cxx_lto.jssize | 2 +- test/other/codesize/test_codesize_cxx_mangle.gzsize | 2 +- test/other/codesize/test_codesize_cxx_mangle.jssize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.gzsize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.jssize | 2 +- test/other/codesize/test_codesize_files_js_fs.gzsize | 2 +- test/other/codesize/test_codesize_files_js_fs.jssize | 2 +- test/other/codesize/test_codesize_hello_dylink.gzsize | 2 +- test/other/codesize/test_codesize_hello_dylink.jssize | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index 7c6c9a1d67b7a..24aca551b4a92 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8167 +8171 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize index ada4fd15d078f..87c594baff5aa 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize @@ -1 +1 @@ -19798 +19802 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index 98d1ee050c7a4..9f96f52ae75be 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8155 +8160 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize index a6f9d33e11ec2..7ed75764695a3 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize @@ -1 +1 @@ -19776 +19780 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index 2f315dd3f6228..be6b7db3622b4 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9154 +9159 diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize index 0933e2ebeb63d..844e4d91ffef1 100644 --- a/test/other/codesize/test_codesize_cxx_except.jssize +++ b/test/other/codesize/test_codesize_cxx_except.jssize @@ -1 +1 @@ -23459 +23463 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index f70da493eb9af..7516f462d51d8 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8115 +8119 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index 62547302be1b9..23f14519610da 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -19687 +19691 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize index f70da493eb9af..7516f462d51d8 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize @@ -1 +1 @@ -8115 +8119 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize index 62547302be1b9..23f14519610da 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize @@ -1 +1 @@ -19687 +19691 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index 0943f904c364b..f9590eeca8c22 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8019 +8023 diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize index ecbbcf8e8d405..39fe2bb8d2412 100644 --- a/test/other/codesize/test_codesize_cxx_lto.jssize +++ b/test/other/codesize/test_codesize_cxx_lto.jssize @@ -1 +1 @@ -19502 +19506 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index a0af512f6bec4..06dcbb22123df 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9171 +9176 diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize index ba08eeeac3781..19a79b009fc79 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.jssize +++ b/test/other/codesize/test_codesize_cxx_mangle.jssize @@ -1 +1 @@ -23509 +23513 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index 7c6c9a1d67b7a..24aca551b4a92 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8167 +8171 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize index ada4fd15d078f..87c594baff5aa 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.jssize +++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize @@ -1 +1 @@ -19798 +19802 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index 60e7ecdcd0ab9..d11cf0e2103c9 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7480 +7485 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index d27086ebb1c76..c335a90029d77 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18401 +18405 diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index b1a76a5094248..b40059dff3b33 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -11562 +11568 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index fb51bc599279b..d8a6faac5143a 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -27310 +27314