From db353d1711622a000af47596104079e000fadd92 Mon Sep 17 00:00:00 2001 From: dsafdsaf132 Date: Mon, 12 Oct 2026 19:59:38 +0900 Subject: [PATCH] fix(install): validate Linux ANGLE libraries and pin node-gyp fallback Check ELF identity and architecture before native linking. Keep fallback compatible with Node 12+ while validating Node 24 builds and integration smoke tests. Review: three independent reviewers; confirmed P2 Node minor-version selection corrected. Remaining P3 follow-ups: full ELF integrity checks and richer filesystem-error diagnostics. --- scripts/install.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/scripts/install.js b/scripts/install.js index a7759ff..8b19b80 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -67,6 +67,30 @@ function validateBundledAngle() { `Bundled ANGLE files are missing for ${platform}-${arch}:\n` + missingFiles.map(file => ` ${file}`).join('\n')); } + if (platform === 'linux') { + for (const name of ['libEGL.so', 'libGLESv2.so', 'libvk_swiftshader.so']) { + const filename = path.join(angleReleasePath, name); + const header = Buffer.alloc(20); + const fd = fs.openSync(filename, 'r'); + let bytesRead; + try { + bytesRead = fs.readSync(fd, header, 0, header.length, 0); + } finally { + fs.closeSync(fd); + } + const machine = arch === 'x64' ? 62 : 183; + if (bytesRead !== header.length || + header.readUInt32BE(0) !== 0x7f454c46 || + header[4] !== 2 || header[5] !== 1 || header[6] !== 1 || + header.readUInt16LE(16) !== 3 || + header.readUInt16LE(18) !== machine) { + throw new Error( + `Invalid ANGLE library for linux-${arch}: ${filename}. ` + + 'Expected a 64-bit little-endian ELF shared library. ' + + 'Reinstall the platform package or restore the bundled libraries.'); + } + } + } console.error(`* Using bundled ANGLE for ${platform}-${arch}`); } @@ -91,8 +115,13 @@ function buildBindings() { try { cp.execSync('node-gyp rebuild', {stdio: 'inherit'}); } catch (err) { - console.error('* node-gyp failed, retrying with npx node-gyp'); - cp.execSync('npx --yes node-gyp rebuild', {stdio: 'inherit'}); + // Keep the fallback compatible with the supported Node releases rather + // than downloading a future node-gyp with a higher Node requirement. + const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(Number); + const gypVersion = nodeMajor >= 18 || + (nodeMajor === 16 && nodeMinor >= 14) ? '10.3.1' : '8.4.1'; + console.error(`* node-gyp failed, retrying with node-gyp@${gypVersion}`); + cp.execSync(`npx --yes node-gyp@${gypVersion} rebuild`, {stdio: 'inherit'}); } copyRequiredWindowsDlls(); }