Skip to content

Add null checks to xnnpack flatbuffer#18799

Merged
lucylq merged 1 commit intomainfrom
security35-37
Apr 10, 2026
Merged

Add null checks to xnnpack flatbuffer#18799
lucylq merged 1 commit intomainfrom
security35-37

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Apr 9, 2026

Add null checks to the flatbuffer graph on:

  • flatbuffer graph itself
  • xnodes
  • xvalues

Check that num_externs is <= num_values

Authored-with: Claude

…_externs

Add null checks for flatbuffer_graph, xvalues(), and xnodes() after
deserialization to prevent NULL pointer dereferences on malformed input.
Validate num_externs does not exceed total number of values to prevent
unbounded memory allocation in xnn_create_subgraph.

Authored-with: Claude
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 9, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18799

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 1 Cancelled Job, 1 Unrelated Failure

As of commit 7b5b1b5 with merge base 21d9c64 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@lucylq lucylq marked this pull request as ready for review April 10, 2026 00:28
@lucylq lucylq requested a review from digantdesai as a code owner April 10, 2026 00:28
Copilot AI review requested due to automatic review settings April 10, 2026 00:28
Copy link
Copy Markdown
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 hardens XNNPACK flatbuffer deserialization in XNNCompiler::compileModel by adding basic validation checks before the graph is consumed, reducing the risk of null dereferences on malformed inputs.

Changes:

  • Add null checks for the deserialized flatbuffer graph and its xvalues/xnodes vectors.
  • Add a consistency check ensuring num_externs <= xvalues()->size() before creating the XNNPACK subgraph.
  • Use the validated num_externs value when calling xnn_create_subgraph.

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

Comment on lines +1847 to +1851
ET_CHECK_OR_RETURN_ERROR(
flatbuffer_graph != nullptr && flatbuffer_graph->xvalues() != nullptr &&
flatbuffer_graph->xnodes() != nullptr,
InvalidProgram,
"Failed to deserialize XNNPACK flatbuffer graph; null graph, xvalues, or xnodes.");
@lucylq lucylq merged commit 59f66cf into main Apr 10, 2026
169 of 182 checks passed
@lucylq lucylq deleted the security35-37 branch April 10, 2026 21:40
lucylq added a commit that referenced this pull request Apr 13, 2026
Internal failures on: #18799

`num_externs <= num_values` is not the right check. We should scan
xvalues to find `num_externs` and use that, provided they are valid.
Will put up separate PR for the change.

Co-authored-by: Github Executorch <github_executorch@arm.com>
jpiat pushed a commit to jpiat/executorch that referenced this pull request Apr 14, 2026
Add null checks to the flatbuffer graph on:
- flatbuffer graph itself
- xnodes
- xvalues

Check that num_externs is <= num_values

Authored-with: Claude

Co-authored-by: Github Executorch <github_executorch@arm.com>
jpiat pushed a commit to jpiat/executorch that referenced this pull request Apr 14, 2026
Internal failures on: pytorch#18799

`num_externs <= num_values` is not the right check. We should scan
xvalues to find `num_externs` and use that, provided they are valid.
Will put up separate PR for the change.

Co-authored-by: Github Executorch <github_executorch@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. security-fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants