Vulnerability: FPE in LSH in TFLite ### Impact
An attacker can craft a TFLite model that would trigger a division by zero error in LSH  [implementation](https://github.com/tensorflow/tensorflow/blob/149562d49faa709ea80df1d99fc41d005b81082a/tensorflow/lite/kernels/lsh_projection.cc#L118).

```cc
int RunningSignBit(const TfLiteTensor* input, const TfLiteTensor* weight,
                   float seed) {
  int input_item_bytes = input->bytes / SizeOfDimension(input, 0);
  // ...
}
```
          
There is no check that the first dimension of the input is non zero.
      
### Patches
We have patched the issue in GitHub commit [0575b640091680cfb70f4dd93e70658de43b94f9](https://github.com/tensorflow/tensorflow/commit/0575b640091680cfb70f4dd93e70658de43b94f9).

The fix will be included in TensorFlow 2.6.0. We will also cherrypick thiscommit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

### For more information
Please consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for  more information regarding the security model and how to contact us with issues and questions.

### Attribution
This vulnerability has been reported by Yakun Zhang of Baidu Security.
Vulnerability ID: GHSA-27qf-jwm8-g7f3
CWE: CWE-369
Severity score: 5.5
Project: https://github.com/tensorflow/tensorflow
Published: 2021-08-25
File: tensorflow/lite/kernels/lsh_projection.cc
Commit message: Prevent division by 0 in LSH projection.

PiperOrigin-RevId: 387225857
Change-Id: Iaeb572a763618c64f503e0026f6dd9fd769bf50c
Commit author: Mihai Maruseac

Vulnerable version (before fix):
 limitations under the License. // // Input: //   Tensor[0]: Hash functions. Dim.size == 2, DataType: Float. //              Tensor[0].Dim[0]: Num of hash functions. //              Tensor[0].Dim[1]: Num of projected output bits generated by //                                each hash function. //   In sparse case, Tensor[0].Dim[1] + ceil( log2(Tensor[0].Dim[0] )) <= 32. TfLiteStatus Resize(TfLiteContext* context, TfLiteNode* node) {   const TfLiteTensor* input;   TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &input));   TF_LITE_ENSURE(context, NumDimensions(input) >= 1);    if (NumInputs(node) == 3) {     const TfLiteTensor* weight;

Fixed version (after fix):
 limitations under the License. // // Input: //   Tensor[0]: Hash functions. Dim.size == 2, DataType: Float. //              Tensor[0].Dim[0]: Num of hash functions. Must be at least 1. //              Tensor[0].Dim[1]: Num of projected output bits generated by //                                each hash function. //   In sparse case, Tensor[0].Dim[1] + ceil( log2(Tensor[0].Dim[0] )) <= 32. TfLiteStatus Resize(TfLiteContext* context, TfLiteNode* node) {   const TfLiteTensor* input;   TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &input));   TF_LITE_ENSURE(context, NumDimensions(input) >= 1);   TF_LITE_ENSURE(context, SizeOfDimension(input, 0) >= 1);    if (NumInputs(node) == 3) {     const TfLiteTensor* weight;

Patch:
patch: @@ -28,7 +28,7 @@ limitations under the License.
 //
 // Input:
 //   Tensor[0]: Hash functions. Dim.size == 2, DataType: Float.
-//              Tensor[0].Dim[0]: Num of hash functions.
+//              Tensor[0].Dim[0]: Num of hash functions. Must be at least 1.
 //              Tensor[0].Dim[1]: Num of projected output bits generated by
 //                                each hash function.
 //   In sparse case, Tensor[0].Dim[1] + ceil( log2(Tensor[0].Dim[0] )) <= 32.
@@ -82,6 +82,7 @@ TfLiteStatus Resize(TfLiteContext* context, TfLiteNode* node) {
   const TfLiteTensor* input;
   TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &input));
   TF_LITE_ENSURE(context, NumDimensions(input) >= 1);
+  TF_LITE_ENSURE(context, SizeOfDimension(input, 0) >= 1);
 
   if (NumInputs(node) == 3) {
     const TfLiteTensor* weight;
path: tensorflow/lite/kernels/lsh_projection.cc