Repository navigation
fix(artifacts): reject non-object GLB JSON roots and non-array images - #14297
Conversation
Stop coercing non-object GLB JSON roots, non-array images members, non-object buffer entries, and explicit null byteOffset values to empty defaults in glbLayout. Non-object roots now report json_status: "invalid" with unknown coverage, and non-array images or invalid image/bufferView/buffer declarations keep coverage unknown with explicit limitations.
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryTightens GLB parsing so malformed JSON shapes no longer look like complete inventories.
Review was based on source inspection; tests were not run. Whether this PR has been superseded could not be checked because GitHub access was unavailable. Reviews (2) · Last reviewed commit: "fix(artifacts): reject non-object GLB JS..." · Reviewed by Greptile |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary
Fixes #14296.
glbLayout(src/artifacts/gpuAsset/GpuAssetLayouts.ts) no longer silently coerces non-object GLB JSON roots, non-arrayimagesmembers, non-objectbuffersentries, or explicitbyteOffset: nullvalues into empty defaults. Non-object JSON roots now reportjson_status: "invalid"andcoverage.status: "unknown", and invalidimages/bufferView/buffer/byteOffsetdeclarations keep coverageunknownwith explicit limitations.Problem and expected behavior
On
origin/main(271bad782),glbLayoutusedrecordOf(...)(coercing any non-object to{}),arrayOf(...)(coercing any non-array to[]), andview["byteOffset"] ?? 0(coercingnullto0):[],null,42,"text",true):parseLastWinsJson(...)returned the valid non-object JSON value,recordOf(...)turned it into{}, andjsonStatuswas set to"parsed", reportingcoverage.status: "complete"andlimitations: []in contradiction to the existing limitation"The GLB JSON chunk is not a readable JSON object; collection counts were not read.".imagesmember ("images": "not-an-array",{},null,0,false):arrayOf(json["images"])treated the invalid member as an empty array without settingregionsExamined = "unknown"or recording a limitation, reportingcoverage.status: "complete".buffers[0](buffers: [null]) and explicitbyteOffset: null:buffers[0]passedbuffer === undefinedandnull ?? 0turnedbyteOffset: nullinto0, listingimages/0.pngwithcoverage.status: "complete".Expected behavior:
json_status: "invalid", setregionsExamined: "unknown", retainchunks/0.json/chunks/1.bin, and emit the existing limitation.imagesproperty is not an array keepsjson_status: "parsed", setsregionsExamined: "unknown", and emits"The GLB images member is not a JSON array; embedded images were not listed.".image/bufferView/bufferentries and explicitbyteOffset: nullor out-of-boundsbyteOffset/byteLengthcount as unresolved images (regionsExamined: "unknown").Change and scope
src/artifacts/gpuAsset/GpuAssetLayouts.ts:recordOf(...)(silent fallback to{}) withasRecord(...)returningReadonly<Record<string, unknown>> | undefined, and extractedreadGlbJsonChunk(...)to keep chunk parsing flat and readable.asRecord(parseLastWinsJson(...)) !== undefinedbefore returning{ status: "parsed", json: parsed }(non-objects return{ status: "invalid", json: {} }, triggeringregionsExamined = "unknown"and the existing non-object JSON limitation).Object.hasOwn(json, "images") && !Array.isArray(json["images"])to markregionsExamined = "unknown"and record"The GLB images member is not a JSON array; embedded images were not listed.".image,bufferViews[viewIndex], andbuffers[bufferIndex]withasRecord(...), treatedview["byteOffset"] === undefined(omitted) separately fromnull, and checkedstart > binLength || length > binLength - startsostart + lengthavoids exceedingNumber.MAX_SAFE_INTEGER.GpuAssetLayouts.ts(ddsLayout,ktxLayout,ktx2Layout— binary headers only, no JSON).src/artifacts/,src/resources/,src/domain/, andsrc/native/parsers/:src/native/parsers/plist.ts(the only other caller ofparseLastWinsJson) explicitly tracksrootKind: "invalid" | "container" | "scalar";src/resources/AsarHeader.tsrejectsjson-not-objectat probe time;src/domain/sourceMapFormat.tsvalidates the root withmapHeaderSchema.Contract and boundary impact
glbLayoutinsrc/artifacts/gpuAsset/GpuAssetLayouts.tsowns GLB JSON chunk interpretation and embedded image region discovery, consumed byGpuAssetArtifactReader(src/artifacts/gpuAsset/GpuAssetArtifactReader.ts) andinspect-artifact/extract-artifact. Removed the silent-coercionrecordOfhelper and replaced it withasRecord.glbMetadataSchemaalready definesjson_status: "parsed" | "invalid" | "limit"andcoverage.status: "complete" | "unknown"). Malformed GLB JSON roots and invalidimagesdeclarations now reportunknowncoverage and limitations instead ofcomplete.GpuAssetArtifactReader/inspect-artifact/extract-artifact.json_status: "parsed"andcoverage.status: "complete"claims while retaining raw chunk regions (chunks/0.json,chunks/1.bin) and valid sibling image regions.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/artifacts/gpuAsset/GpuAssetLayouts.test.ts(new, 21 tests): covers all five non-object JSON roots ([],null,42,"text",true), valid object controls (omittedimages,images: [], embedded image with omittedbyteOffsetat exactbinLengthalongside URI external images), five non-arrayimagestypes (string,object,null,number,boolean), and eight invalid image/bufferView/buffer/byteOffset shapes (non-objectimages[0]preservingimages/1.png, non-arraybufferViews, non-objectbufferView, non-arraybuffers, non-objectbuffers[0], explicitbyteOffset: null,byteOffset > binLengthwithbyteLength: 0, andbyteOffset + byteLength = binLength + 1).src/artifacts/gpuAsset/GpuAssetArtifactReader.test.ts: adds 2 tests verifyingGpuAssetArtifactReaderon a non-object JSON root ([]) andinventoryArtifacton a non-arrayimagesmember ({}).tests/acceptance/gpuAssetHeadersCli.test.ts: adds 1 compiled CLI test verifyingrea inspect-artifact <array-root.glb> --jsonexits 0 withcoverage.status: "unknown",format_metadata.json_status: "invalid", and the non-object JSON limitation.271bad782, fix3edfaa153):271bad782):npm run test:local -- src/artifacts/gpuAsset/GpuAssetLayouts.test.ts src/artifacts/gpuAsset/GpuAssetArtifactReader.test.ts-> 14 failed | 38 passed (52) (GpuAssetLayouts.test.ts: 12 failed / 9 passed;GpuAssetArtifactReader.test.ts: 2 failed / 29 passed).3edfaa153:52 passed (52) (
GpuAssetLayouts.test.ts: 21/21 passed;GpuAssetArtifactReader.test.ts: 31/31 passed).271bad782..3edfaa153: 27/30 killed againstnpm run test:local -- src/artifacts/gpuAsset/GpuAssetLayouts.test.ts(all newly introduced guards killed; the 3 surviving lines are the 2 TypeScript return-type annotation lines ofreadGlbJsonChunkstripped by Vitest and enforced bytsc, plus the pre-existinglength > GLB_JSON_PARSE_BYTEScheck moved unchanged intoreadGlbJsonChunk).rea inspect-artifact array-root.glb --jsonnow outputscoverage.status: "unknown",limitations: ["The GLB JSON chunk is not a readable JSON object; collection counts were not read."], and rootformat_metadata.json_status: "invalid"instead ofcomplete/parsed(verified intests/acceptance/gpuAssetHeadersCli.test.ts).6.9.0binary labeled6.10.1in an ignoredmanifest.json) to satisfy build checks;GpuAssetLayoutsandGpuAssetArtifactReaderare pure TypeScript and do not invoke the native addon.Boundary regressions covered: non-object JSON roots, non-array
imagesmembers, non-object nestedimage/bufferView/bufferrecords, explicitbyteOffset: nullvs omittedbyteOffset, exactbinLength(MAX) vsbinLength + 1(MAX + 1), and preservation of valid sibling regions when an invalid sibling is present. Lifecycle regressions are not applicable because no descriptors, processes, or cleanup stages were modified.For evidence-bearing changes:
Validation performed
npm run test:local -- src/artifacts/gpuAsset/GpuAssetLayouts.test.ts src/artifacts/gpuAsset/GpuAssetArtifactReader.test.ts— passed (2 files, 52/52 tests).npm run test:focused -- tests/acceptance/gpuAssetHeadersCli.test.ts— passed (1 file, 7/7 compiled CLI tests).npm run check:fast— passed (typecheck,lint, andverify:architecture-guardsacross 3085 source files).Compatibility, safety, and release
images/bufferViews/buffersdeclarations continue to reportjson_status: "parsed"andcoverage.status: "complete".start + lengthexceedingNumber.MAX_SAFE_INTEGER; no new dependencies, network calls, or process launches.Author readiness
Human owner: @Plastic-time
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.