Skip to content
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

fix for div zero #34724

Merged
merged 3 commits into from
Aug 10, 2021
Merged

fix for div zero #34724

merged 3 commits into from
Aug 10, 2021

Conversation

zh794390558
Copy link
Contributor

@zh794390558 zh794390558 commented Aug 9, 2021

PR types

Bug fixes

PR changes

OPs

Describe

fix for div zero error

functional.ctc_loss存在除0异常
调用paddle.nn.functional.ctc_loss进行计算的时候,在sequence_padding.cc中存在除0异常。

PoC:

import paddle
from paddle.nn import TransformerEncoderLayer
import numpy as np

input_arr = np.array([], dtype=np.float32)
log_probs = paddle.to_tensor(np.reshape(input_arr, (3, 0, 19)), dtype='float32')

labels_arr = np.array([], dtype=np.float32)
labels = paddle.to_tensor(np.reshape(input_arr, (0, 0)), dtype='float32')

input_lengths = paddle.to_tensor([], dtype='float32')

label_lengths = paddle.to_tensor([], dtype='float32')

paddle.nn.functional.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0)
ASAN Info:

==162441==ERROR: AddressSanitizer: FPE on unknown address 0x7f3bb9b98db4 (pc 0x7f3bb9b98db4 bp 0x7ffc8f998740 sp 0x7ffc8f9985c0 T0)
#0 0x7f3bb9b98db4 in paddle::operators::math::UnpaddingLoDTensorFunctor<paddle::platform::CPUDeviceContext, int>::operator()(paddle::platform::CPUDeviceContext const&, paddle::framework::LoDTensor const&, paddle::framework::LoDTensor*, int, int, bool, paddle::operators::math::PadLayout) /home/work/yakun/py-paddle/Paddle/paddle/fluid/operators/math/sequence_padding.cc:152:42
#1 0x7f3bb118672d in paddle::operators::WarpCTCKernel<paddle::platform::CPUDeviceContext, float>::Compute(paddle::framework::ExecutionContext const&) const /home/work/yakun/py-paddle/Paddle/paddle/fluid/operators/warpctc_op.h:321:9
#2 0x7f3bb1181fae in paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CPUPlace, false, 0ul, paddle::operators::WarpCTCKernel<paddle::platform::CPUDeviceContext, float>, paddle::operators::WarpCTCKernel<paddle::platform::CPUDeviceContext, double> >::operator()(char const*, char const*, int) const::'lambda'(paddle::framework::ExecutionContext const&)::operator()(paddle::framework::ExecutionContext const&) const /home/work/yakun/py-paddle/Paddle/paddle/fluid/framework/op_registry.h:182:25
#3 0x7f3bb1181fae in std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CPUPlace, false, 0ul, paddle::operators::WarpCTCKernel<paddle::platform::CPUDeviceContext, float>, paddle::operators::WarpCTCKernel<paddle::platform::CPUDeviceContext, double> >::operator()(char const*, char const*, int) const::'lambda'(paddle::framework::ExecutionContext const&)>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:297:2
#4 0x7f3bbb5b56dc in std::function<void (paddle::framework::ExecutionContext const&)>::operator()(paddle::framework::ExecutionContext const&) const /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:687:14
Python version: 3.8

paddlepaddle版本:Develop (2021-07-14 pull)

漏洞代码
paddlepaddle develop中,代码位置:https://sourcegraph.com/github.com/PaddlePaddle/Paddle@develop/-/blob/paddle/fluid/operators/math/sequence_padding.cc?L152

问题代码:

int step_width = seq_tensor->numel() / seq_tensor_dims[0];
其中,由于没做check,seq_tensor_dims[0]为0,触发异常

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 9, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@XiaoguangHu01 XiaoguangHu01 merged commit d86c26d into PaddlePaddle:develop Aug 10, 2021
@zh794390558 zh794390558 deleted the ctc_safe_err branch August 10, 2021 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants