Skip to content

Validate array-typed members before array access during deserialization#176

Open
SergioRZMasson wants to merge 2 commits into
microsoft:masterfrom
SergioRZMasson:sergioze/validate-array-members-master
Open

Validate array-typed members before array access during deserialization#176
SergioRZMasson wants to merge 2 commits into
microsoft:masterfrom
SergioRZMasson:sergioze/validate-array-members-master

Conversation

@SergioRZMasson

Copy link
Copy Markdown
Contributor

Validates array-typed glTF members before reading them with rapidjson array/element accessors.

Problem

ParseNodeChildren (node children) and RapidJsonUtils::ToFloatArray (node weights and mesh weights) read rapidjson array size/capacity/element accessors and per-element number accessors without first confirming the member is a JSON array of the expected element type.

rapidjson's array and number accessors are only well-defined once the value's type has been checked (in release builds the type asserts are compiled out). When schema validation is disabled, a present member of a different JSON type — for example a string supplied where an array is expected — reaches these accessors, and the value's storage is read as array metadata rather than being rejected.

Fix

  • RapidJsonUtils::ToFloatArray now throws InvalidGLTFException unless the member is a JSON array whose elements are all numbers. Node weights and mesh weights share this helper, so the guard is centralized there.
  • ParseNodeChildren now throws InvalidGLTFException unless children is a JSON array of unsigned integers.

Absent optional members are still accepted (unchanged), and valid arrays deserialize exactly as before.

Tests

Adds positive and negative regression tests in GLTFSDK.Test for node children, node weights and mesh weights, covering both a wrong container type (non-array) and a wrong element type (non-number / non-index). The negative tests use SchemaFlags::DisableSchemaRoot so the malformed value reaches the semantic deserializers — a consumer that disables JSON-schema validation must still get a clean InvalidGLTFException rather than undefined behaviour.

Validation

Full GLTFSDK.Test suite passes on Windows x64 and Win32, Debug and RelWithDebInfo: 353/353.

SergioRZMasson and others added 2 commits July 15, 2026 15:13
…lization

Cover node children, node weights and mesh weights: a present member of the
wrong container type, or an array element of the wrong type, must throw
InvalidGLTFException. Includes positive coverage that valid arrays still
deserialize. Tests currently fail against the unguarded parser.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 039828de-4db2-48f8-a5de-c9f7d33baffa
Node children and node/mesh weights were read with rapidjson array and
element accessors without first confirming the member is a JSON array of
the expected element type. A present member of a different JSON type - or
an array element of the wrong type - is now rejected with
InvalidGLTFException before any array/number accessor is used.

Node weights and mesh weights share RapidJsonUtils::ToFloatArray, so the
element-type guard is centralized in that helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 039828de-4db2-48f8-a5de-c9f7d33baffa
@SergioRZMasson
SergioRZMasson requested a review from bghgary July 15, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants