Commit ce2d95a
committed
Fix stack buffer overflows in ynnpack channelwise quantized tensor and reduce
Bug 1: xnn_define_channelwise_quantized_tensor_value_v3 (tensor.cc:146)
std::copy_n(dims, channel_dim + 1, quantization_dims) copies channel_dim + 1
elements into quantization_dims[YNN_MAX_TENSOR_RANK] (size 8) without checking
channel_dim < num_dims or channel_dim < YNN_MAX_TENSOR_RANK. With
channel_dim >= 8, this writes past the stack buffer.
ASAN trace:
==ERROR: AddressSanitizer: stack-buffer-overflow
WRITE of size 88
#8 xnn_define_channelwise_quantized_tensor_value_v3
[96, 160) 'quantization_dims' (line 145) <== overflows this variable
Fix: Add channel_dim >= num_dims and num_dims > YNN_MAX_TENSOR_RANK checks.
Bug 2: get_reduce_identity_value (reduce.cc:243)
For ynn_reduce_min_max with keep_dims=true on a rank-8 tensor,
output.extents.push_back(2) increases rank to 9. Then dims[rank - 1] = dims[8]
writes one element past the size-8 stack array.
Fix: Add rank bounds check before array access.1 parent e0fe33a commit ce2d95a
2 files changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
243 | 246 | | |
244 | 247 | | |
245 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
| |||
0 commit comments