Skip to content

Fix GltfLoader JSON size limits and ShaderCache key validation centralization#359

Merged
ormidales merged 3 commits into1.1.14from
copilot/sub-pr-358
Mar 13, 2026
Merged

Fix GltfLoader JSON size limits and ShaderCache key validation centralization#359
ormidales merged 3 commits into1.1.14from
copilot/sub-pr-358

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

  • Read and analyze review comments
  • Fix GltfLoader: validate maxJsonBufferBytes/maxJsonStringBytes are finite and non-negative (NaN/Infinity/negative → RangeError)
  • Fix GltfLoader: add chunk length overflow bounds check in parseGlb (extends beyond file → clear error)
  • Fix tests: use getUint32(12, true) to read actual GLB chunk size from header instead of re-stringify
  • Add 6 new tests covering the new validations
  • Run tests — 409/409 pass
  • Code review — no issues
  • CodeQL security scan — 0 alerts

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

- Split maxJsonBufferBytes into separate raw-byte and decoded-string limits
  (new maxJsonStringBytes option, defaults to maxJsonBufferBytes * 2) to
  avoid unexpectedly halving the ASCII payload limit
- Apply maxJsonBufferBytes and maxJsonStringBytes bounds inside parseGlb
  for the GLB JSON chunk, closing the resource-exhaustion gap on the GLB path
- Centralize explicit key length validation in ShaderCache.assertKeyLength()
  private helper; replace three duplicated inline checks in getShader,
  getProgram, and getProgramKey
- Update tests: rename string-guard test to use maxJsonStringBytes, add
  independence test, and add two GLB JSON chunk size limit tests

Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
Copilot AI changed the title [WIP] Release v1.1.14 with security policy improvements Fix GltfLoader JSON size limits and ShaderCache key validation centralization Mar 13, 2026
Copilot AI requested a review from ormidales March 13, 2026 21:10
@ormidales ormidales added this to the v1.1.14 milestone Mar 13, 2026
@ormidales ormidales marked this pull request as ready for review March 13, 2026 21:12
Copilot AI review requested due to automatic review settings March 13, 2026 21:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens glTF/GLB container parsing limits in GltfLoader by separating raw-byte vs decoded-string heap guards (and applying them to GLB JSON chunks), and removes duplicated explicit-key length checks in ShaderCache by centralizing validation.

Changes:

  • Introduces maxJsonStringBytes (defaulting to maxJsonBufferBytes * 2) to decouple raw UTF-8 size limits from decoded UTF-16 heap footprint checks.
  • Applies both size bounds to the GLB JSON chunk path in parseGlb.
  • Extracts ShaderCache.assertKeyLength(key) and routes getShader, getProgram, and getProgramKey through it.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/core/GltfLoader.ts Adds independent raw/decoded JSON limits and enforces them for both .gltf and GLB JSON chunks.
src/core/ShaderCache.ts Centralizes explicit cache-key length validation into a single helper.
tests/gltf.test.ts Updates/extends tests to cover maxJsonStringBytes and GLB JSON chunk bounds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ormidales
Copy link
Owner

@copilot apply changes based on the comments in this thread

…tle test

- Validate maxJsonBufferBytes and maxJsonStringBytes in parseContainer:
  NaN, Infinity, or negative values now throw a RangeError immediately,
  preventing the size guards from being silently disabled
- Add chunk length overflow bounds check in parseGlb: verify
  offset+8+chunkLength <= buffer.byteLength before slicing; malformed
  or truncated GLBs now throw a clear 'extends beyond end of file' error
- Fix brittle GLB chunk size test: use getUint32(12, true) to read the
  actual on-disk JSON chunk length from the GLB header instead of
  re-stringifying the parsed result (which can differ due to padding)
- Add 6 new tests: NaN/Infinity/negative for both limits, and
  chunk-extends-beyond-file

Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot apply changes based on the comments in this thread

All three review comments addressed in commit 209675a:

  1. NaN/invalid options (GltfLoader.ts:264-266): parseContainer now validates both maxJsonBufferBytes and maxJsonStringBytes with Number.isFinite(...) && ... >= 0 immediately after resolving the values. NaN, Infinity, or negative inputs throw a RangeError with a clear message before any comparison is attempted.

  2. Chunk bounds check (GltfLoader.ts:318): parseGlb now checks offset + 8 + chunkLength > buffer.byteLength before slicing. Malformed or truncated GLBs throw 'GLB chunk at offset N extends beyond end of file ...'.

  3. Brittle test (tests/gltf.test.ts:212-215): Now uses new DataView(glb).getUint32(12, true) to read the JSON chunk length directly from the GLB header, independent of stringify ordering or padding.

6 new tests added covering: NaN, Infinity, negative for both limits, and the chunk-extends-beyond-file error.

Copilot AI requested a review from ormidales March 13, 2026 21:21
@ormidales ormidales merged commit febc750 into 1.1.14 Mar 13, 2026
2 checks passed
@ormidales ormidales deleted the copilot/sub-pr-358 branch March 13, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants