Conversation
Summary: This diff reverts D100115639 T264111177 Depends on D100115639 Differential Revision: D100228771
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18800
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 Cancelled Job, 2 Unrelated FailuresAs of commit 906fe30 with merge base ecd97d5 ( BROKEN TRUNK - The following jobs 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. |
|
@lucylq has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100228771. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
This PR reverts a prior change (D100115639) in the extension data loaders, primarily backing out use of c10::safe_numerics overflow-checked arithmetic and simplifying some bounds checks/error text.
Changes:
- Removed
c10/util/safe_numerics.husage and the explicit add-overflow validation from several DataLoader implementations. - Replaced overflow-safe range validation with direct
offset + size <= ...checks. - Simplified an error message in
BufferDataLoaderto no longer mention overflow.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| extension/data_loader/shared_ptr_data_loader.h | Drops overflow-safe bounds check for shared-buffer loads. |
| extension/data_loader/mmap_data_loader.cpp | Drops overflow-safe validation for mmap read ranges. |
| extension/data_loader/file_descriptor_data_loader.cpp | Drops overflow-safe validation for file-descriptor read ranges (load/load_into). |
| extension/data_loader/file_data_loader.cpp | Drops overflow-safe validation for file read ranges (load/load_into). |
| extension/data_loader/buffer_data_loader.h | Updates error message text while still using overflow detection. |
Comments suppressed due to low confidence (8)
extension/data_loader/mmap_data_loader.cpp:169
offset + size <= file_size_is not overflow-safe: ifoffset + sizewraps, validation can incorrectly succeed, and laterget_overlapping_pages()also doesoffset + sizearithmetic that can overflow. Prefer an overflow-safe check likeoffset <= file_size_ && size <= file_size_ - offset(or use an explicit add-overflow helper).
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_name_,
offset,
size,
file_size_);
extension/data_loader/file_descriptor_data_loader.cpp:167
- This bounds check is vulnerable to
size_twraparound (offset + sizecan overflow and become small), which can allow out-of-bounds reads. Use an overflow-safe formulation such asoffset <= file_size_ && size <= file_size_ - offset, or an explicit add-overflow check.
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_descriptor_uri_,
offset,
size,
file_size_);
extension/data_loader/file_descriptor_data_loader.cpp:228
- Same overflow issue here:
offset + size <= file_size_can wrap and bypass validation. Use an overflow-safe check (offset <= file_size_ && size <= file_size_ - offset) or an explicit add-overflow helper before callingpread.
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_descriptor_uri_,
offset,
size,
file_size_);
extension/data_loader/file_data_loader.cpp:153
offset + size <= file_size_can overflow and wrap, allowing invalid ranges to pass validation. Prefer an overflow-safe check such asoffset <= file_size_ && size <= file_size_ - offset, or use an explicit add-overflow helper.
ET_CHECK_OR_RETURN_ERROR(
// Probably had its value moved to another instance.
fd_ >= 0,
InvalidState,
"Uninitialized");
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_name_,
offset,
size,
file_size_);
extension/data_loader/file_data_loader.cpp:214
- Same overflow concern in
load_into:offset + sizecan wrap and bypass the bounds check, potentially leading to incorrect reads. Use an overflow-safe check (offset <= file_size_ && size <= file_size_ - offset) or an explicit add-overflow helper.
ET_CHECK_OR_RETURN_ERROR(
// Probably had its value moved to another instance.
fd_ >= 0,
InvalidState,
"Uninitialized");
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_name_,
offset,
size,
file_size_);
extension/data_loader/mmap_data_loader.cpp:170
- Consider adding a unit test that verifies
validate_input/loadrejects ranges whereoffset + sizewould overflow (wraparound). This module has OOB tests already, but overflow-specific coverage would prevent regressions.
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_name_,
offset,
size,
file_size_);
return Error::Ok;
extension/data_loader/file_data_loader.cpp:153
- The existing FileDataLoader tests cover out-of-bounds ranges but not integer-overflow ranges. Add a regression test that uses a huge
size(e.g.,SIZE_MAX - offset + 1) and expects InvalidArgument, to ensure wraparound can’t bypass the bounds check.
ET_CHECK_OR_RETURN_ERROR(
// Probably had its value moved to another instance.
fd_ >= 0,
InvalidState,
"Uninitialized");
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_name_,
offset,
size,
file_size_);
extension/data_loader/file_descriptor_data_loader.cpp:167
- The test suite covers out-of-bounds loads but doesn’t appear to cover the
offset + sizewraparound case. Add an overflow regression test (similar to BufferDataLoaderTest.OverflowLoadFails) to ensure the bounds check can’t be bypassed via integer overflow.
ET_CHECK_OR_RETURN_ERROR(
offset + size <= file_size_,
InvalidArgument,
"File %s: offset %zu + size %zu > file_size_ %zu",
file_descriptor_uri_,
offset,
size,
file_size_);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ET_CHECK_OR_RETURN_ERROR( | ||
| !overflow && total_size <= size_, | ||
| offset + size <= size_, | ||
| InvalidArgument, | ||
| "offset %zu + size %zu > size_ %zu, or overflow detected", | ||
| "offset %zu + size %zu > size_ %zu", | ||
| offset, | ||
| size, | ||
| size_); |
There was a problem hiding this comment.
The bounds check offset + size <= size_ can overflow size_t and wrap, allowing an out-of-bounds slice to pass validation. Use an overflow-safe check (e.g., offset <= size_ && size <= size_ - offset) or __builtin_add_overflow/similar to reject wrapped additions.
| !overflow && total_size <= size_, | ||
| InvalidArgument, | ||
| "offset %zu + size %zu > size_ %zu, or overflow detected", | ||
| "offset %zu + size %zu > size_ %zu", |
There was a problem hiding this comment.
The check still uses c10::add_overflows(...) and fails when overflow is detected, but the error message no longer mentions overflow. Either restore the message text to include overflow, or restructure the validation so the message matches the actual failure conditions.
| "offset %zu + size %zu > size_ %zu", | |
| "offset %zu + size %zu overflows or exceeds size_ %zu", |
| ET_CHECK_OR_RETURN_ERROR( | ||
| !overflow && total_size <= size_, | ||
| offset + size <= size_, | ||
| InvalidArgument, | ||
| "offset %zu + size %zu > size_ %zu, or overflow detected", | ||
| "offset %zu + size %zu > size_ %zu", | ||
| offset, | ||
| size, | ||
| size_); |
There was a problem hiding this comment.
There are out-of-bounds tests for SharedPtrDataLoader, but no regression test for the offset + size overflow case. Add a unit test that passes values like offset=128, size=SIZE_MAX-127 and expects InvalidArgument, so future refactors don’t reintroduce wraparound bugs.
Summary:
This diff reverts D100115639
T264111177
Depends on D100115639
Differential Revision: D100228771