diff --git a/src/node_sea.cc b/src/node_sea.cc index 1be41e6f14146e..b0382479b183d3 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -537,6 +537,14 @@ std::optional ParseSingleExecutableConfig( } } + if (!document.at_end()) { + FPrintF(stderr, + "Cannot parse JSON from %s: %s\n", + config_path, + simdjson::error_message(simdjson::TRAILING_CONTENT)); + return std::nullopt; + } + if (static_cast(result.flags & SeaFlags::kUseSnapshot) && static_cast(result.flags & SeaFlags::kUseCodeCache)) { // TODO(joyeecheung): code cache in snapshot should be configured by diff --git a/test/sea/test-single-executable-blob-config-errors.js b/test/sea/test-single-executable-blob-config-errors.js index 322f430aad81d6..9562faad6b79d7 100644 --- a/test/sea/test-single-executable-blob-config-errors.js +++ b/test/sea/test-single-executable-blob-config-errors.js @@ -47,6 +47,24 @@ const { spawnSyncAndAssert } = require('../common/child_process'); }); } +{ + tmpdir.refresh(); + const config = tmpdir.resolve('trailing-content.json'); + writeFileSync( + config, + '{"main":"bundle.js","output":"sea.blob"}{}', + 'utf8', + ); + spawnSyncAndAssert( + process.execPath, + ['--experimental-sea-config', config], { + cwd: tmpdir.path, + }, { + status: 1, + stderr: /TRAILING_CONTENT/, + }); +} + { tmpdir.refresh(); const config = tmpdir.resolve('empty.json');