diff options
author | Xusong Wang <xusongw@google.com> | 2019-06-11 14:42:56 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2019-06-11 14:42:56 -0700 |
commit | 3ca1c4d963d0007fe2b90dc5ef97bfee4b3f805a (patch) | |
tree | 8bc37c0d804e4cc92defed4426ccf15100d4a9e4 | |
parent | 024c11aa748f15a8ec179a786801fe5ae0f188ac (diff) | |
download | ml-3ca1c4d963d0007fe2b90dc5ef97bfee4b3f805a.tar.gz |
Fix PRELU underflow/overflow issue.
The quant8 results should be clamped by 0 and 255 before static casting
to uint8_t.
Bug: 134800353
Test: NeuralNetworksTest_static_fuzzing
Change-Id: I1bc8f386782c67158edd3da2f663fee5746dda48
-rw-r--r-- | nn/common/operations/PRelu.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/nn/common/operations/PRelu.cpp b/nn/common/operations/PRelu.cpp index 0bf4ce65d..68d1e5bcc 100644 --- a/nn/common/operations/PRelu.cpp +++ b/nn/common/operations/PRelu.cpp @@ -86,6 +86,7 @@ bool evalQuant8(const uint8_t* aData, const Shape& aShape, const uint8_t* bData, tflite::MultiplyByQuantizedMultiplier( input * alpha, output_multiplier_neg, output_shift_neg); } + output_val = std::max(0, std::min(255, output_val)); return static_cast<uint8_t>(output_val); }, aData, aShape, bData, bShape, outputData, outputShape); |