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

解决Node读取Js文件未设置编码造成的vm.run()运行报错问题和vm.runInContext()方法不存在造成的运行报错问题 #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gowther
Copy link

@Gowther Gowther commented Nov 27, 2021

  1. 本地Node版本为v12.18.3,根据Node官方文档说明, fs.readFileSync(path, endcoding)方法,不传encoding时方法返回的是二进制buffer,126行 vm.run(code) vm运行时会报错。
    If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
  2. 根据vm2官方文档说明,没有找到 vm.runInContext()方法, 160 行运行报错。
    What is the difference between Node's vm and vm2?
const vm = require('vm');
vm.runInNewContext('this.constructor.constructor("return process")().exit()');
const {VM} = require('vm2');
new VM().run('this.constructor.constructor("return process")().exit()');

1. 本地Node版本v12.18.3,根据Node官方文档(https://nodejs.org/api/fs.html#fsreaddirsyncpath-options)说明,fs.readFileSync(path, endcoding)方法,不传encoding时方法返回的是二进制的buffer,126行 vm.run(code) 运行时会报错
2. 根据vm2官方文档(https://github.com/patriksimek/vm2)说明,找不到 vm.runInContext()方法, 160 行运行报错
What is the difference between Node's vm and vm2?
const vm = require('vm');
vm.runInNewContext('this.constructor.constructor("return process")().exit()');
const {VM} = require('vm2');
new VM().run('this.constructor.constructor("return process")().exit()');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant