Commit 7185963
Account for current pointer being outside of the buffer (#316)
Summary:
Pull Request resolved: #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: D651188961 parent 373d1c5 commit 7185963
1 file changed
+6
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
0 commit comments