Skip to content

update the fs.readFileSync integrity check expectation #31927

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions scripts/binary/binary-integrity-check-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) {

if (stack.length !== options.stackToMatch.length) {
console.error(`Integrity check failed with expected stack length ${options.stackToMatch.length} but got ${stack.length}`)

throw new Error(integrityErrorMessage)
}

// console.log('expected stack frames:', JSON.stringify(options.stackToMatch, null, 2))
// for (const expectedStackFrame of options.stackToMatch) {
// console.log(' ', JSON.stringify(expectedStackFrame, null, 2))
// }

// console.log('actual stack frames:')
// for (const actualStackFrame of stack) {
// console.log(' ', JSON.stringify({
// functionName: actualStackFrame.getFunctionName(),
// fileName: actualStackFrame.getFileName(),
// line: actualStackFrame.getLineNumber(),
// column: actualStackFrame.getColumnNumber(),
// }, null, 2))
// }

for (let index = 0; index < options.stackToMatch.length; index++) {
const { functionName: expectedFunctionName, fileName: expectedFileName, line: expectedLineNumber, column: expectedColumnNumber } = options.stackToMatch[index]
const actualFunctionName = stack[index].getFunctionName()
Expand Down Expand Up @@ -65,21 +81,21 @@ const stackIntegrityCheck = function stackIntegrityCheck (options) {

function validateStartsWith () {
if (originalStartsWith.call !== originalCallFn) {
console.error(`Integrity check failed for startsWith.call`)
console.error(`Integrity check failed for startsWith.call ${originalStartsWith.call}`)
throw new Error(integrityErrorMessage)
}
}

function validateFilter () {
if (originalFilter.call !== originalCallFn) {
console.error(`Integrity check failed for filter.call`)
console.error(`Integrity check failed for filter.call ${originalFilter.call}`)
throw new Error(integrityErrorMessage)
}
}

function validateToString () {
if (originalToString.call !== originalCallFn) {
console.error(`Integrity check failed for toString.call`)
console.error(`Integrity check failed for toString.call ${originalToString.call}`)
throw new Error(integrityErrorMessage)
}
}
Expand All @@ -94,7 +110,7 @@ function validateElectron (electron) {

function validateFs (fs) {
// Hard coded function as this is electron code and there's not an easy way to get the function string at package time. If this fails on an updated version of electron, we'll need to update this.
if (originalToString.call(fs.readFileSync) !== `function(e,r){const n=splitPath(e);if(!n.isAsar)return w.apply(this,arguments);const{asarPath:i,filePath:a}=n,o=getOrCreateArchive(i);if(!o)throw createError("INVALID_ARCHIVE",{asarPath:i});const c=o.getFileInfo(a);if(!c)throw createError("NOT_FOUND",{asarPath:i,filePath:a});if(0===c.size)return r?"":s.Buffer.alloc(0);if(c.unpacked){const e=o.copyFileOut(a);return t.readFileSync(e,r)}if(r){if("string"==typeof r)r={encoding:r};else if("object"!=typeof r)throw new TypeError("Bad arguments")}else r={encoding:null};const{encoding:f}=r,l=s.Buffer.alloc(c.size),u=o.getFdAndValidateIntegrityLater();if(!(u>=0))throw createError("NOT_FOUND",{asarPath:i,filePath:a});return logASARAccess(i,a,c.offset),t.readSync(u,l,0,c.size,c.offset),validateBufferIntegrity(l,c.integrity),f?l.toString(f):l}`) {
if (originalToString.call(fs.readFileSync) !== `function(t,e){const r=splitPath(t);return r.isAsar?readFileFromArchiveSync(r,e):R.apply(this,arguments)}`) {
console.error(`Integrity check failed for toString.call(fs.readFileSync)`)
throw new Error(integrityErrorMessage)
}
Expand Down Expand Up @@ -190,6 +206,10 @@ function integrityCheck (options) {
line: 1,
column: 2764,
},
{
functionName: 'traceSync',
fileName: 'node:diagnostics_channel',
},
],
})

Expand Down
6 changes: 4 additions & 2 deletions scripts/binary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ async function testExecutableVersion (buildAppExecutable, version) {
la(result.stdout, 'missing output when getting built version', result)

console.log('built app version', result.stdout)
la(result.stdout.trim() === version.trim(), 'different version reported',
result.stdout, 'from input version to build', version)
la(
result.stdout.trim() === version.trim(),
`different version reported: '${result.stdout.trim()}' from input version to build '${version.trim()}'`,
)

console.log('✅ using --version on the Cypress binary works')
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/binary/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) {
await fs.remove(path.join(buildAppDir, 'index2.js'))
}

await testAlteringEntryPoint('console.log("simple alteration")', 'Integrity check failed with expected stack length 9 but got 10')
await testAlteringEntryPoint('console.log("simple alteration")', 'Integrity check failed with expected stack length 10 but got 12')
await testAlteringEntryPoint('console.log("accessing " + global.getSnapshotResult())', 'getSnapshotResult can only be called once')

function compareGlobals () {
Expand All @@ -299,9 +299,9 @@ const runIntegrityTest = async function (buildAppExecutable, buildAppDir, e2e) {
console.error(`extra keys in electron process: ${extraKeys}`)
}

const allowList = ['__core-js_shared__', 'getSnapshotResult', 'supportTypeScript', 'Iterator']
const allowList = ['__core-js_shared__', 'getSnapshotResult', 'supportTypeScript', 'SuppressedError', 'DisposableStack', 'AsyncDisposableStack', 'Float16Array']

await testAlteringEntryPoint(`(${compareGlobals.toString()})()`, `extra keys in electron process: ${allowList}\nIntegrity check failed with expected stack length 9 but got 10`)
await testAlteringEntryPoint(`(${compareGlobals.toString()})()`, `extra keys in electron process: ${allowList}\nIntegrity check failed with expected stack length 10 but got 12`)

const testTemporarilyRewritingEntryPoint = async () => {
const file = path.join(buildAppDir, 'index.js')
Expand Down
1 change: 1 addition & 0 deletions scripts/binary/trigger-publish-binary-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { getNextVersionForBinary } = require('../get-next-version')
const { nextVersion } = await getNextVersionForBinary()

const body = JSON.stringify({
branch: 'electron-36',
parameters: {
temp_dir: os.tmpdir(),
sha: process.env.CIRCLE_SHA1,
Expand Down
Loading