Repository navigation
Commit dd503e2
authored
Fix null pointer dereference in MethodMeta::uses_backend() (pytorch#22405)
Fixes pytorch#22404
### Summary
`MethodMeta::uses_backend()` dereferenced `ExecutionPlan::delegates()`
without a null check. Per `schema/program.fbs`, `delegates` has no
default and can be legitimately unset. `num_backends()`, six lines below
in the same file, already guards this exact condition — this PR applies
the same guard to `uses_backend()`.
See pytorch#22404 for the full root-cause writeup, reproduction, and crash
output.
### Test plan
Added `MethodMetaTest.UsesBackendOnUnsetDelegatesReturnsFalse` to
`runtime/executor/test/method_meta_test.cpp`, constructing a minimal,
self-contained, schema-valid `Program` (via
`flatbuffers::FlatBufferBuilder` + `BufferDataLoader`) where `delegates`
is left unset, then asserting `uses_backend()` returns `false` instead
of crashing.
Verified locally (Clang, Debug, `-fsanitize=address,undefined`):
- Without the fix: the new test crashes with an ASan/UBSan SIGSEGV on
`flatbuffers::Vector::size()` inside `uses_backend()`.
- With the fix: the new test passes, and the full `method_meta_test`
suite (7/7 tests) passes with no regressions.
- Also ran the neighboring `program_test`, `method_test`, and
`memory_manager_test` suites via `ctest` — all passing, no side effects
from this change.
Commands used:
```
cmake --build build-test --target method_meta_test
.\build-test\runtime\executor\test\method_meta_test.exe
ctest --test-dir build-test -R "method_meta_test|memory_manager_test|program_test|method_test" --output-on-failure
```
cc @larryliu0820 @JacobSzwejbka @lucylq1 parent 751481b commit dd503e2
4 files changed
Lines changed: 96 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
406 | 409 | | |
407 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
408 | 414 | | |
409 | 415 | | |
410 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
82 | 94 | | |
83 | 95 | | |
84 | 96 | | |
| |||
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
| 107 | + | |
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
| |||
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
133 | | - | |
134 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
135 | 159 | | |
136 | 160 | | |
137 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
| |||
275 | 282 | | |
276 | 283 | | |
277 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
180 | 181 | | |
| 182 | + | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
| |||
0 commit comments