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
fix: add column, line, and method check to integrity check #25094
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c534ac4
fix: add column, line, and method check to integrity check
ryanthemanuel ca01c3e
run ci
ryanthemanuel 6efb3ae
add test
ryanthemanuel 1c59a4c
run ci
ryanthemanuel ab85363
run ci
ryanthemanuel b71ec81
fix test
ryanthemanuel 4a9bcc0
harden logic
ryanthemanuel 8aafe38
trim down what is used from bytenode
ryanthemanuel fe28249
pr comments
ryanthemanuel ea697f6
fix smoke test
ryanthemanuel 54a630a
Merge branch 'develop' into ryanm/fix/column-line
ryanthemanuel 082b495
fix build
ryanthemanuel a833145
fix build
ryanthemanuel a29c08c
Update cache-version.txt
ryanthemanuel 8cebd44
Merge branch 'develop' into ryanm/fix/column-line
ryanthemanuel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Bump this version to force CI to re-create the cache from scratch. | ||
|
||
12-05-22 | ||
12-12-22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
diff --git a/node_modules/bytenode/lib/cli.js b/node_modules/bytenode/lib/cli.js | ||
index 9f57493..3ba173e 100755 | ||
--- a/node_modules/bytenode/lib/cli.js | ||
+++ b/node_modules/bytenode/lib/cli.js | ||
@@ -2,11 +2,15 @@ | ||
|
||
'use strict'; | ||
|
||
-const fs = require('fs'); | ||
-const path = require('path'); | ||
-const wrap = require('module').wrap; | ||
-const spawnSync = require('child_process').spawnSync; | ||
-const bytenode = require('./index.js'); | ||
+import fs from 'fs'; | ||
+import path from 'path'; | ||
+import * as mod from 'module'; | ||
+import { spawnSync } from 'child_process'; | ||
+import * as bytenode from './index.js'; | ||
+import * as url from 'url'; | ||
+ | ||
+const __filename = url.fileURLToPath(import.meta.url); | ||
+const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
const args = process.argv.slice(2); | ||
|
||
@@ -100,7 +104,7 @@ if (program.flags.includes('--compile')) { | ||
if (program.flags.includes('--no-module')) { | ||
process.stdout.write(bytenode.compileCode(script)); | ||
} else { | ||
- process.stdout.write(bytenode.compileCode(wrap(script))); | ||
+ process.stdout.write(bytenode.compileCode(mod.wrap(script))); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
@@ -136,13 +140,6 @@ if (program.flags.includes('--compile')) { | ||
$ echo 'console.log("Hello");' | bytenode --compile - > hello.jsc | ||
compile from stdin and save to \`hello.jsc\` | ||
`); | ||
-} else if (program.flags.includes('--version') && program.flags.length === 1 && program.files.length === 0) { | ||
- const pkg = require('../package.json'); | ||
- console.log(pkg.name, pkg.version); | ||
- console.log('Node', process.versions.node); | ||
- if (process.versions.electron) { | ||
- console.log('Electron', process.versions.electron); | ||
- } | ||
} else { | ||
try { | ||
spawnSync(program.nodeBin, [ | ||
diff --git a/node_modules/bytenode/lib/index.js b/node_modules/bytenode/lib/index.js | ||
index cdd98cc..635bc27 100644 | ||
--- a/node_modules/bytenode/lib/index.js | ||
+++ b/node_modules/bytenode/lib/index.js | ||
@@ -1,11 +1,13 @@ | ||
'use strict'; | ||
|
||
-const fs = require('fs'); | ||
-const vm = require('vm'); | ||
-const v8 = require('v8'); | ||
-const path = require('path'); | ||
-const Module = require('module'); | ||
-const fork = require('child_process').fork; | ||
+import fs from 'fs'; | ||
+import vm from 'vm'; | ||
+import v8 from 'v8'; | ||
+import path from 'path'; | ||
+import Module from 'module'; | ||
+import { fork } from 'child_process'; | ||
+import { createRequire } from 'module'; | ||
+import * as url from 'url'; | ||
|
||
v8.setFlagsFromString('--no-lazy'); | ||
|
||
@@ -46,10 +48,12 @@ const compileElectronCode = function (javascriptCode) { | ||
return new Promise((resolve, reject) => { | ||
let data = Buffer.from([]); | ||
|
||
+ const require = createRequire(import.meta.url) | ||
const electronPath = path.join(path.dirname(require.resolve('electron')), 'cli.js'); | ||
if (!fs.existsSync(electronPath)) { | ||
throw new Error('Electron not installed'); | ||
} | ||
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
const bytenodePath = path.join(__dirname, 'cli.js'); | ||
|
||
// create a subprocess in which we run Electron as our Node and V8 engine | ||
@@ -249,7 +253,7 @@ const runBytecodeFile = function (filename) { | ||
return runBytecode(bytecodeBuffer); | ||
}; | ||
|
||
-Module._extensions[COMPILED_EXTNAME] = function (fileModule, filename) { | ||
+const runBytecodeAsModule = function (fileModule, filename) { | ||
const bytecodeBuffer = fs.readFileSync(filename); | ||
|
||
fixBytecode(bytecodeBuffer); | ||
@@ -333,14 +337,13 @@ const loaderCode = function (targetPath) { | ||
`; | ||
}; | ||
|
||
-global.bytenode = { | ||
+export { | ||
compileCode, | ||
compileFile, | ||
compileElectronCode, | ||
runBytecode, | ||
runBytecodeFile, | ||
addLoaderFile, | ||
- loaderCode | ||
+ loaderCode, | ||
+ runBytecodeAsModule, | ||
}; | ||
- | ||
-module.exports = global.bytenode; | ||
diff --git a/node_modules/bytenode/package.json b/node_modules/bytenode/package.json | ||
index 6caff7c..72e2c46 100644 | ||
--- a/node_modules/bytenode/package.json | ||
+++ b/node_modules/bytenode/package.json | ||
@@ -3,6 +3,7 @@ | ||
"version": "1.3.7", | ||
"description": "A minimalist bytecode compiler for Node.js", | ||
"main": "lib/index.js", | ||
+ "type": "module", | ||
"bin": "lib/cli.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why we create all these aliases in the first place instead of just doing
tempError.filter(...
) etc? It looks like something to do with the integrity check - how does comparingif (filter.call !== callFn) {
verify the integrity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are protecting against the prototype call method on each of those functions being tampered with. So we want to make sure that they are still equal to the original function call prior to using them