Skip to content

runtime/executor: null-check backend_delegate_data#19904

Open
vacu9708 wants to merge 1 commit into
pytorch:mainfrom
vacu9708:null-check_backend_delegate_data
Open

runtime/executor: null-check backend_delegate_data#19904
vacu9708 wants to merge 1 commit into
pytorch:mainfrom
vacu9708:null-check_backend_delegate_data

Conversation

@vacu9708
Copy link
Copy Markdown
Contributor

This PR continues the loader-hardening work in #16704, #18724, and #19267.

Bug

backend_delegate_data is an optional FlatBuffer vector (schema/program.fbs:506, no (required) attribute).

flowchart LR
    A["Method::load\nmethod.cpp:839"] -->|"for each BackendDelegate"| B["GetProcessedData\nmethod.cpp:193"]
    B -->|"location == INLINE"| C["get_backend_delegate_data\nprogram.cpp:534"]
    C -->|"backend_delegate_data() == null"| D["SIGSEGV"]
Loading

Fix

Add a null guard before the existing size check:

Condition Before After
backend_delegate_data() is null SIGSEGV InvalidProgram
entry->data() is null SIGSEGV InvalidProgram

InvalidProgram is used (rather than NotFound) because an absent backend_delegate_data while a delegate references inline data indicates a corrupt file, not a normal lookup miss. Happy to change if you prefer NotFound for symmetry with the index check.

The GetProcessedData function has two structurally parallel unguarded derefs (delegate.processed(), delegate.id()->c_str()); left for a follow-up to keep this PR focused.

Tests

$ cmake --build cmake-out --target program_test -j$(nproc)
[100%] Built target program_test

$ cd cmake-out && ctest -R '^program_test$'
100% tests passed, 0 tests failed out of 1

$ lintrunner runtime/executor/program.cpp runtime/executor/test/program_test.cpp
ok No lint issues.

`backend_delegate_data` is an optional FlatBuffer vector — legitimately
absent when no inline delegate blobs exist. The accessor dereferenced it
without a null check, causing a SIGSEGV on any such PTE. Neither the
FlatBuffer verifier nor validate_program catches this, so the crash was
reachable under both Minimal and InternalConsistency verification.

- Add `data_list != nullptr` guard; return `InvalidProgram` if absent.
- Add `data != nullptr` guard on the per-entry data field.

Continues the loader-hardening work in pytorch#16704, pytorch#18724, and pytorch#19267.

Signed-off-by: Youngsik Yang <vacu9708@gmail.com>
@vacu9708 vacu9708 requested a review from JacobSzwejbka as a code owner May 31, 2026 11:24
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 31, 2026

🔗 Helpful Links

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

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

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 May 31, 2026
@github-actions
Copy link
Copy Markdown

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.

@vacu9708 vacu9708 changed the title runtime/executor: null-check backend_delegate_data` runtime/executor: null-check backend_delegate_data May 31, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants