Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix a null pointer exception caused by branching on uninitialized data.
This is due to not checking that the params for the quantization exists. If there is no quantization, we should not access the `.params` field.

PiperOrigin-RevId: 385168337
Change-Id: I28661e4f12ba1c92cfeae23d22a3fb2df2a2c6a4
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Jul 16, 2021
1 parent 0e956f7 commit 4a91f20
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tensorflow/lite/kernels/unidirectional_sequence_lstm.cc
Expand Up @@ -62,8 +62,12 @@ TfLiteStatus PopulateQuantizedLstmParams8x8_16(
context,
GetOutputSafe(context, node, lstm::full::kOutputTensor, &output_tensor));

TF_LITE_ENSURE(context,
cell_state->quantization.type != kTfLiteNoQuantization);
auto* cell_state_params =
static_cast<TfLiteAffineQuantization*>(cell_state->quantization.params);
TF_LITE_ENSURE(context,
output_tensor->quantization.type != kTfLiteNoQuantization);
auto* proj_params = static_cast<TfLiteAffineQuantization*>(
output_tensor->quantization.params);
if (cell_clip > 0.0) {
Expand Down Expand Up @@ -160,6 +164,8 @@ TfLiteStatus PopulateQuantizedLstmParams8x8_16(
TfLiteTensor* intermediate;
TF_LITE_ENSURE_OK(context,
GetIntermediatesSafe(context, node, i, &intermediate));
TF_LITE_ENSURE(context,
intermediate->quantization.type != kTfLiteNoQuantization);
auto* params = static_cast<TfLiteAffineQuantization*>(
intermediate->quantization.params);
intermediate_scale.push_back(params->scale->data[0]);
Expand All @@ -174,6 +180,7 @@ TfLiteStatus PopulateQuantizedLstmParams8x8_16(
// is ignored.
TfLiteTensor* hidden;
TF_LITE_ENSURE_OK(context, GetIntermediatesSafe(context, node, 4, &hidden));
TF_LITE_ENSURE(context, hidden->quantization.type != kTfLiteNoQuantization);
auto* hidden_params =
static_cast<TfLiteAffineQuantization*>(hidden->quantization.params);
intermediate_scale.push_back(hidden_params->scale->data[0]);
Expand Down Expand Up @@ -760,6 +767,8 @@ TfLiteStatus PopulatePrecomputedZPTimesWeightsWithBias(TfLiteContext* context,

const TfLiteTensor* intermediate =
&context->tensors[node->intermediates->data[4]];
TF_LITE_ENSURE(context,
intermediate->quantization.type != kTfLiteNoQuantization);
const auto* params =
static_cast<TfLiteAffineQuantization*>(intermediate->quantization.params);
const int32_t hidden_zp = params->zero_point->data[0];
Expand Down

0 comments on commit 4a91f20

Please sign in to comment.