-
Notifications
You must be signed in to change notification settings - Fork 955
Add bounds checking on buffer_idx for constant_buffer and constant_data in XNNPACK #18820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -170,10 +170,12 @@ std::vector<T> flatbufferDimsToVector( | |||||||||||||||||||
| /** | ||||||||||||||||||||
| Gets the constant data pointer associated with the given tensor value. | ||||||||||||||||||||
| Obtaining the constant data pointer can either be from within the flatbuffer | ||||||||||||||||||||
| payload (deprecated) or via offsets to the constant_data_ptr. If no constant | ||||||||||||||||||||
| data associated with the tensor value, then returns nullptr. | ||||||||||||||||||||
| payload (deprecated) or via offsets to the constant_data_ptr. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Failures are returned as an Error, and the successful value may be nullptr | ||||||||||||||||||||
| when the tensor has no associated constant data. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| const uint8_t* getConstantDataPtr( | ||||||||||||||||||||
| Result<const uint8_t*> getConstantDataPtr( | ||||||||||||||||||||
| uint32_t buffer_idx, | ||||||||||||||||||||
| GraphPtr flatbuffer_graph, | ||||||||||||||||||||
| const uint8_t* constant_data_ptr, | ||||||||||||||||||||
|
|
@@ -184,26 +186,56 @@ const uint8_t* getConstantDataPtr( | |||||||||||||||||||
| if (!constant_data_ptr) { | ||||||||||||||||||||
| // TODO(T172265611): Remove constant_buffer in flatbuffer path after BC | ||||||||||||||||||||
| // window | ||||||||||||||||||||
| const auto& constant_buffer = *flatbuffer_graph->constant_buffer(); | ||||||||||||||||||||
| return constant_buffer[buffer_idx]->storage()->data(); | ||||||||||||||||||||
| auto* cb = flatbuffer_graph->constant_buffer(); | ||||||||||||||||||||
| ET_CHECK_OR_RETURN_ERROR( | ||||||||||||||||||||
| cb != nullptr, InvalidProgram, "constant_buffer is null"); | ||||||||||||||||||||
| ET_CHECK_OR_RETURN_ERROR( | ||||||||||||||||||||
| buffer_idx < cb->size(), | ||||||||||||||||||||
| InvalidProgram, | ||||||||||||||||||||
| "buffer_idx %u out of bounds for constant_buffer of size %zu", | ||||||||||||||||||||
| buffer_idx, | ||||||||||||||||||||
| cb->size()); | ||||||||||||||||||||
| auto* buffer_entry = (*cb)[buffer_idx]; | ||||||||||||||||||||
| ET_CHECK_OR_RETURN_ERROR( | ||||||||||||||||||||
| buffer_entry != nullptr && buffer_entry->storage() != nullptr, | ||||||||||||||||||||
| InvalidProgram, | ||||||||||||||||||||
| "Null constant_buffer entry at buffer_idx %u", | ||||||||||||||||||||
| buffer_idx); | ||||||||||||||||||||
| return buffer_entry->storage()->data(); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| ConstantDataOffsetPtr constant_data_offset = | ||||||||||||||||||||
| flatbuffer_graph->constant_data()->Get(buffer_idx); | ||||||||||||||||||||
| auto* cd = flatbuffer_graph->constant_data(); | ||||||||||||||||||||
| ET_CHECK_OR_RETURN_ERROR( | ||||||||||||||||||||
| cd != nullptr, InvalidProgram, "constant_data is null"); | ||||||||||||||||||||
| ET_CHECK_OR_RETURN_ERROR( | ||||||||||||||||||||
| buffer_idx < cd->size(), | ||||||||||||||||||||
| InvalidProgram, | ||||||||||||||||||||
| "buffer_idx %u out of bounds for constant_data of size %zu", | ||||||||||||||||||||
| buffer_idx, | ||||||||||||||||||||
| cd->size()); | ||||||||||||||||||||
|
lucylq marked this conversation as resolved.
Comment on lines
+210
to
+214
|
||||||||||||||||||||
| ConstantDataOffsetPtr constant_data_offset = cd->Get(buffer_idx); | ||||||||||||||||||||
|
||||||||||||||||||||
| ConstantDataOffsetPtr constant_data_offset = cd->Get(buffer_idx); | |
| ConstantDataOffsetPtr constant_data_offset = cd->Get(buffer_idx); | |
| if (constant_data_offset == nullptr) { | |
| ET_LOG( | |
| Error, | |
| "Invalid null constant_data entry at buffer_idx %u", | |
| buffer_idx); | |
| return nullptr; | |
| } |
Uh oh!
There was an error while loading. Please reload this page.