Skip to content

Account for current pointer being outside of the buffer #316

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

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

scotts
Copy link
Contributor

@scotts scotts commented Oct 29, 2024

Summary:
D60461269 added TORCH_CHECK to catch negative values. This would catch the input argument buf_size being negative.

However, it never caught the case of bufferData->current pointer being past bufferData->size. This is due to intricacies of C++ type rules. Both current and size are size_t (unsigned integers), which causes the subtraction to always be non-negative.

This example demonstrates above well.

If we only had read method the current would never be able to go past size, but we have seek method that can set current to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Differential Revision: D65118896

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 29, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65118896

scotts pushed a commit to scotts/torchcodec that referenced this pull request Nov 4, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: scotts, ahmadsharif1

Differential Revision: D65118896
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65118896

facebook-github-bot pushed a commit that referenced this pull request Nov 4, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: scotts, ahmadsharif1

Differential Revision: D65118896
facebook-github-bot pushed a commit that referenced this pull request Nov 5, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: scotts, ahmadsharif1

Differential Revision: D65118896
facebook-github-bot pushed a commit that referenced this pull request Nov 5, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: scotts, ahmadsharif1

Differential Revision: D65118896
facebook-github-bot pushed a commit that referenced this pull request Nov 5, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: scotts, ahmadsharif1

Differential Revision: D65118896
scotts added a commit to scotts/torchcodec that referenced this pull request Nov 5, 2024
Summary:

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: ahmadsharif1

Differential Revision: D65118896
Summary:
Pull Request resolved: pytorch#316

D60461269 added `TORCH_CHECK` to catch negative values. This would catch the input argument `buf_size` being negative.

However, it never caught the case of `bufferData->current` pointer being past `bufferData->size`. This is due to intricacies of C++ type rules. Both `current` and `size` are `size_t` (unsigned integers), which causes the subtraction to always be non-negative.

[This example](https://www.programiz.com/online-compiler/3zokStBbD2TeP) demonstrates above well.

If we only had `read` method the `current` would never be able to go past `size`, but we have `seek` method that can set `current` to arbitrary values.

The diff here makes sure that we actually catch these negative values and fail with reasonable error instead of segfaulting trying to read memory outside of the buffer.

Reviewed By: ahmadsharif1

Differential Revision: D65118896
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65118896

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D65118896

@facebook-github-bot facebook-github-bot merged commit 3c2c129 into pytorch:main Nov 6, 2024
39 of 42 checks passed
@scotts scotts deleted the export-D65118896 branch January 25, 2025 01:12
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 Meta Open Source bot. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants