Skip to content

3D engine that AI agents drive

Fix the four open CodeQL alerts on main (#1968)

Nguyen Xuan Ande7515410008
diff --git a/scripts/proof-spring-bones.mjs b/scripts/proof-spring-bones.mjs
index 495e7fc4..572579aa 100644
--- a/scripts/proof-spring-bones.mjs
+++ b/scripts/proof-spring-bones.mjs
@@ -16,6 +16,7 @@ import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
const FOX_URL = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models/Fox/glTF-Binary/Fox.glb';
// The file is written to disk only when it matches this hash.
const FOX_SHA256 = 'd97044e701822bac5a62696459b27d7b375aada5de8574ed4362edbba94771f7';
+const FOX_MAXIMUM_BYTES = 4 * 1024 * 1024;
const outputDirectory = resolve(process.argv[2] ?? 'artifacts/981');
const backend = process.env.PROOF_BACKEND ?? 'gpu';
const WIDTH = 640;
@@ -30,7 +31,28 @@ const jobs = join(workDirectory, 'jobs');
await mkdir(assets);
await mkdir(outputDirectory, { recursive: true });
-const foxBytes = Buffer.from(await (await fetch(FOX_URL)).arrayBuffer());
+async function downloadBounded(url, maximumBytes) {
+ const response = await fetch(url);
+ if (!response.ok) {
+ throw new Error(`Downloading ${url} failed with HTTP ${response.status}. Check the network and that the file still exists.`);
+ }
+ const declaredBytes = Number(response.headers.get('content-length'));
+ if (declaredBytes > maximumBytes) {
+ throw new Error(`${url} declares ${declaredBytes} bytes, over the ${maximumBytes} byte limit. Check that FOX_URL still points at the Fox model.`);
+ }
+ const chunks = [];
+ let receivedBytes = 0;
+ for await (const chunk of response.body) {
+ receivedBytes += chunk.length;
+ if (receivedBytes > maximumBytes) {
+ throw new Error(`${url} sent more than the ${maximumBytes} byte limit. Check that FOX_URL still points at the Fox model.`);
+ }
+ chunks.push(chunk);
+ }
+ return Buffer.concat(chunks);
+}
+
+const foxBytes = await downloadBounded(FOX_URL, FOX_MAXIMUM_BYTES);
const assetId = createHash('sha256').update(foxBytes).digest('hex');
if (assetId !== FOX_SHA256) {
throw new Error(`The downloaded Fox.glb has sha256 ${assetId}, expected ${FOX_SHA256}. Check the file at ${FOX_URL} and update FOX_SHA256 only if the new file is the same fox.`);
diff --git a/tests/agent-motion-look.test.js b/tests/agent-motion-look.test.js
index 6acd0d29..6a0152b9 100644
--- a/tests/agent-motion-look.test.js
+++ b/tests/agent-motion-look.test.js
@@ -183,7 +183,7 @@ test('an environment track on a key light field names the sun track that animate
const expectedSunProperties = { keyIntensity: 'intensity', keyColor: 'color', keyDirection: 'direction' };
for (const [property, sunProperty] of Object.entries(expectedSunProperties)) {
const track = { kind: 'environment', property, keyframes: keys(1, 2) };
- assert.throws(() => createAgentScene(sceneRecipe([track])), new RegExp(`The key light is the sun kind: use \{ "kind": "sun", "property": "${sunProperty}" \}`));
+ assert.throws(() => createAgentScene(sceneRecipe([track])), new RegExp(`The key light is the sun kind: use { "kind": "sun", "property": "${sunProperty}" }`));
}
const unrelated = { kind: 'environment', property: 'sunColor', keyframes: keys(1, 2) };
assert.throws(() => createAgentScene(sceneRecipe([unrelated])), error => !/sun kind/.test(error.message));
diff --git a/tests/support/review-page-dom.mjs b/tests/support/review-page-dom.mjs
index 5cf67489..e74ebbc1 100644
--- a/tests/support/review-page-dom.mjs
+++ b/tests/support/review-page-dom.mjs
@@ -77,7 +77,7 @@ class FakeElement {
* (what the Save file button would write), and the elements. The stage is shown at its natural pixel size.
*/
export function openReviewPage(html) {
- const scripts = [...html.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g)];
+ const scripts = [...html.matchAll(/<script([^>]*)>([\s\S]*?)<\/script\s*>/gi)];
const config = scripts.find(([, type]) => type.includes('application/json'))[2];
const code = scripts.find(([, type]) => type.trim() === '')[2];
const { width, height } = JSON.parse(config);