Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in module_wrap.cc with malformed loader #33441

Closed
targos opened this issue May 16, 2020 · 3 comments
Closed

Crash in module_wrap.cc with malformed loader #33441

targos opened this issue May 16, 2020 · 3 comments
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@targos
Copy link
Member

targos commented May 16, 2020

loader.mjs:

export function transformSource() {
  return {
    source: {
      boom: true,
    },
  };
}

test.mjs:

import fs from 'fs';
> node --loader ./loader.mjs test.mjs
C:\Program Files\PowerShell\7\pwsh.exe[28872]: c:\ws\src\module_wrap.cc:131: Assertion `args[2]->IsString()' failed.
@targos targos added confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. labels May 16, 2020
@himself65
Copy link
Member

C:\Users\Himself65\Desktop\github\test\33441>node --trace-warnings --loader ./module.mjs test.mjs
(node:27700) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
    at emitExperimentalWarning (internal/util.js:183:11)
    at Object.initializeLoader (internal/process/esm_loader.js:52:3)
    at runMainESM (internal/modules/run_main.js:45:20)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:68:5)
    at internal/main/run_main_module.js:17:47
  - node  --trace-warnings --loader ./module.mjs test.mjs[27700]: c:\ws\src\module_wrap.cc:131: Assertion `args[2]->IsString()' failed.
 1: 00007FF6BD16CEDF v8::internal::wasm::DisjointAllocationPool::~DisjointAllocationPool+74383
 2: 00007FF6BD115A16 v8::base::CPU::has_sse+62326
 3: 00007FF6BD115D91 v8::base::CPU::has_sse+63217
 4: 00007FF6BD146F27 node::Stop+15447
 5: 00007FF6BD925E3F v8::internal::Builtins::builtin_handle+330191
 6: 00007FF6BD92506C v8::internal::Builtins::builtin_handle+326652
 7: 00007FF6BD9256B2 v8::internal::Builtins::builtin_handle+328258
 8: 00007FF6BD925513 v8::internal::Builtins::builtin_handle+327843
 9: 00007FF6BDA0356D v8::internal::SetupIsolateDelegate::SetupHeap+466093
10: 00007FF6BD9974F1 v8::internal::SetupIsolateDelegate::SetupHeap+23601
11: 00007FF6BDA7FACB v8::internal::SetupIsolateDelegate::SetupHeap+975371
12: 00007FF6BD99B708 v8::internal::SetupIsolateDelegate::SetupHeap+40520
13: 00007FF6BD9C8A00 v8::internal::SetupIsolateDelegate::SetupHeap+225600
14: 00007FF6BDA4455E v8::internal::SetupIsolateDelegate::SetupHeap+732318
15: 00007FF6BD9BB66D v8::internal::SetupIsolateDelegate::SetupHeap+171437
16: 00007FF6BD9991DC v8::internal::SetupIsolateDelegate::SetupHeap+31004
17: 00007FF6BD87CEAD v8::internal::Execution::CallWasm+1933
18: 00007FF6BD87CFBB v8::internal::Execution::CallWasm+2203
19: 00007FF6BD87DAFA v8::internal::Execution::TryCall+378
20: 00007FF6BD85E4F5 v8::internal::MicrotaskQueue::RunMicrotasks+501
21: 00007FF6BD85E250 v8::internal::MicrotaskQueue::PerformCheckpoint+32
22: 00007FF6BD18DC29 node::CallbackScope::~CallbackScope+777
23: 00007FF6BD18DFAD node::CallbackScope::~CallbackScope+1677
24: 00007FF6BD18618A v8::internal::compiler::Operator::EffectOutputCount+234
25: 00007FF6BD10CC15 v8::base::CPU::has_sse+25973
26: 00007FF6BD100E41 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+45297
27: 00007FF6BD1C1337 uv_timer_stop+775
28: 00007FF6BD1BDD3B uv_async_send+331
29: 00007FF6BD1BD4CC uv_loop_init+1228
30: 00007FF6BD1BD678 uv_run+216
31: 00007FF6BD0CFC95 EVP_CIPHER_CTX_buf_noconst+40117
32: 00007FF6BD142830 node::Start+288
33: 00007FF6BCFA66FC RC4_options+339452
34: 00007FF6BDEB782C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+156812
35: 00007FF9BB966FD4 BaseThreadInitThunk+20
36: 00007FF9BC91CEC1 RtlUserThreadStart+33

@devsnek
Copy link
Member

devsnek commented May 17, 2020

this should fix it up:

diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
index a7252c1c99..a59e8f9373 100644
--- a/lib/internal/modules/esm/translators.js
+++ b/lib/internal/modules/esm/translators.js
@@ -85,7 +85,7 @@ translators.set('module', async function moduleStrategy(url) {
     source, { url, format: 'module' }, defaultTransformSource));
   maybeCacheSourceMap(url, source);
   debug(`Translating StandardModule ${url}`);
-  const module = new ModuleWrap(url, undefined, source, 0, 0);
+  const module = new ModuleWrap(url, undefined, `${source}`, 0, 0);
   moduleWrap.callbackMap.set(module, {
     initializeImportMeta,
     importModuleDynamically,

@himself65
Copy link
Member

#32202 fixes this

now, it will output:

\node\Release\node.exe --loader ./module.mjs C:\Users\Himself65\Desktop\github\test\33441\test.mjs
(node:21912) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected array buffer, or typed array to be returned for the "source" from the "transformSource" function but got instance of Object.
    at assertBufferSource (internal/modules/esm/translators.js:60:9)
    at stringify (internal/modules/esm/translators.js:70:3)
    at Loader.moduleStrategy (internal/modules/esm/translators.js:119:12)
    at async link (internal/modules/esm/module_job.js:41:21) {
  code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'
}

Process finished with exit code 1

closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants