Skip to content

Commit

Permalink
[QAT] Check the value of numel to avoid segfault (pytorch#81547)
Browse files Browse the repository at this point in the history
Fixes pytorch#78123

### Original Result

Segmentation fault

### Result after fix

RuntimeError: numel is out of the bound of input tensor
Pull Request resolved: pytorch#81547
Approved by: https://github.com/kit1980
  • Loading branch information
hguandl authored and pytorchmergebot committed Nov 24, 2022
1 parent 22a1b5e commit b515c1d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aten/src/ATen/native/quantized/QTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ std::tuple<Tensor, Tensor> choose_qparams_optimized(
const double ratio,
int64_t bit_width) {

if (numel < 0 || numel > input_tensor.numel()) {
TORCH_CHECK(false, "numel is out of the bound of input tensor");
}

TORCH_CHECK(numel <= input_tensor.numel(), "numel ", numel,
" greater than input_tensor.numel() ", input_tensor.numel());
const float* input_row = input_tensor.data_ptr<float>();
Expand Down

0 comments on commit b515c1d

Please sign in to comment.