FPE in BatchMatMul
Hi @SiriusHsh, I'm getting a different error, this is with branch r2.14 and gcc, my bazel is more up to date (6.1.0):

```
./benchmark_model --graph=BatchMatMul_FPE.tflite
2023-09-22 20:08:07.554231: I tensorflow/tools/benchmark/benchmark_model.cc:475] Graph: [BatchMatMul_FPE.tflite]
2023-09-22 20:08:07.554309: I tensorflow/tools/benchmark/benchmark_model.cc:476] Init ops:
2023-09-22 20:08:07.554321: I tensorflow/tools/benchmark/benchmark_model.cc:477] Input layers: [input:0]
2023-09-22 20:08:07.554329: I tensorflow/tools/benchmark/benchmark_model.cc:478] Input shapes: [1,224,224,3]
2023-09-22 20:08:07.554337: I tensorflow/tools/benchmark/benchmark_model.cc:479] Input types: [float]
2023-09-22 20:08:07.554344: I tensorflow/tools/benchmark/benchmark_model.cc:480] Output layers: [output:0]
2023-09-22 20:08:07.554352: I tensorflow/tools/benchmark/benchmark_model.cc:481] Target layers: []
2023-09-22 20:08:07.554376: I tensorflow/tools/benchmark/benchmark_model.cc:482] Num runs: [1000]
2023-09-22 20:08:07.554398: I tensorflow/tools/benchmark/benchmark_model.cc:483] Inter-inference delay (seconds): [-1.0]
2023-09-22 20:08:07.554417: I tensorflow/tools/benchmark/benchmark_model.cc:484] Inter-benchmark delay (seconds): [-1.0]
2023-09-22 20:08:07.554433: I tensorflow/tools/benchmark/benchmark_model.cc:486] Num threads: [-1]
2023-09-22 20:08:07.554448: I tensorflow/tools/benchmark/benchmark_model.cc:487] Benchmark name: []
2023-09-22 20:08:07.554457: I tensorflow/tools/benchmark/benchmark_model.cc:488] Output prefix: []
2023-09-22 20:08:07.554471: I tensorflow/tools/benchmark/benchmark_model.cc:489] Show sizes: [0]
2023-09-22 20:08:07.554488: I tensorflow/tools/benchmark/benchmark_model.cc:490] Warmup runs: [1]
2023-09-22 20:08:07.554502: I tensorflow/tools/benchmark/benchmark_model.cc:256] Loading TensorFlow.
2023-09-22 20:08:07.554521: I tensorflow/tools/benchmark/benchmark_model.cc:264] Got config, 0 devices
2023-09-22 20:08:07.554619: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
[libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:1: Invalid control characters encountered in text.
[libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:9: Invalid control characters encountered in text.
[libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:45: Interpreting non ascii codepoint 132.
[libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:45: Message type "tensorflow.GraphDef" has no field named "TFL3".
2023-09-22 20:08:07.564334: E tensorflow/tools/benchmark/benchmark_model.cc:275] Could not create TensorFlow Graph: DATA_LOSS: Can't parse BatchMatMul_FPE.tflite as text proto
2023-09-22 20:08:07.564384: I tensorflow/tools/benchmark/benchmark_model.cc:502] Initialized session in 0.009869s
```

Did you upload the right file? Can you try with an updated Bazel? This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61901">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61901">No</a>
 > Hi @SiriusHsh, I'm getting a different error, this is with branch r2.14 and gcc, my bazel is more up to date (6.1.0):
> 
> ```
> ./benchmark_model --graph=BatchMatMul_FPE.tflite
> 2023-09-22 20:08:07.554231: I tensorflow/tools/benchmark/benchmark_model.cc:475] Graph: [BatchMatMul_FPE.tflite]
> 2023-09-22 20:08:07.554309: I tensorflow/tools/benchmark/benchmark_model.cc:476] Init ops:
> 2023-09-22 20:08:07.554321: I tensorflow/tools/benchmark/benchmark_model.cc:477] Input layers: [input:0]
> 2023-09-22 20:08:07.554329: I tensorflow/tools/benchmark/benchmark_model.cc:478] Input shapes: [1,224,224,3]
> 2023-09-22 20:08:07.554337: I tensorflow/tools/benchmark/benchmark_model.cc:479] Input types: [float]
> 2023-09-22 20:08:07.554344: I tensorflow/tools/benchmark/benchmark_model.cc:480] Output layers: [output:0]
> 2023-09-22 20:08:07.554352: I tensorflow/tools/benchmark/benchmark_model.cc:481] Target layers: []
> 2023-09-22 20:08:07.554376: I tensorflow/tools/benchmark/benchmark_model.cc:482] Num runs: [1000]
> 2023-09-22 20:08:07.554398: I tensorflow/tools/benchmark/benchmark_model.cc:483] Inter-inference delay (seconds): [-1.0]
> 2023-09-22 20:08:07.554417: I tensorflow/tools/benchmark/benchmark_model.cc:484] Inter-benchmark delay (seconds): [-1.0]
> 2023-09-22 20:08:07.554433: I tensorflow/tools/benchmark/benchmark_model.cc:486] Num threads: [-1]
> 2023-09-22 20:08:07.554448: I tensorflow/tools/benchmark/benchmark_model.cc:487] Benchmark name: []
> 2023-09-22 20:08:07.554457: I tensorflow/tools/benchmark/benchmark_model.cc:488] Output prefix: []
> 2023-09-22 20:08:07.554471: I tensorflow/tools/benchmark/benchmark_model.cc:489] Show sizes: [0]
> 2023-09-22 20:08:07.554488: I tensorflow/tools/benchmark/benchmark_model.cc:490] Warmup runs: [1]
> 2023-09-22 20:08:07.554502: I tensorflow/tools/benchmark/benchmark_model.cc:256] Loading TensorFlow.
> 2023-09-22 20:08:07.554521: I tensorflow/tools/benchmark/benchmark_model.cc:264] Got config, 0 devices
> 2023-09-22 20:08:07.554619: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
> To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
> [libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:1: Invalid control characters encountered in text.
> [libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:9: Invalid control characters encountered in text.
> [libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:45: Interpreting non ascii codepoint 132.
> [libprotobuf ERROR external/com_google_protobuf/src/google/protobuf/text_format.cc:337] Error parsing text-format tensorflow.GraphDef: 1:45: Message type "tensorflow.GraphDef" has no field named "TFL3".
> 2023-09-22 20:08:07.564334: E tensorflow/tools/benchmark/benchmark_model.cc:275] Could not create TensorFlow Graph: DATA_LOSS: Can't parse BatchMatMul_FPE.tflite as text proto
> 2023-09-22 20:08:07.564384: I tensorflow/tools/benchmark/benchmark_model.cc:502] Initialized session in 0.009869s
> ```
> 
> Did you upload the right file? Can you try with an updated Bazel?

I'm sorry for the delayed response. I don't think it's a Bazel version issue. It's possible that the way I'm building differs from yours.

I'm using the build method recommended in [this official guide](https://www.tensorflow.org/lite/guide/build_cmake#step_1_install_cmake_tool), as follows:
1. git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
2. mkdir tflite_build
cd tflite_build
3. cmake ../tensorflow_src/tensorflow/lite
4. cmake --build . -j
5. cmake --build . -j -t benchmark_model

The benchmark is in the tools directory
I still encounter the same issue in the latest code, commit id: abbbcb50208cf6d5a965b7bf60efec5bb078e142. Hi @SiriusHsh, I wasn't able to reproduce this one:

```sh
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build
cd tflite_build
cmake ../tensorflow_src/tensorflow/lite
cmake --build . -j
cmake --build . -j -t benchmark_model
cd tools/benchmark
cp path/to/BatchMatMul_FPE.tflite .
./benchmark_model --graph=BatchMatMul_FPE.tflite
```
```
./benchmark_model --graph=BatchMatMul_FPE.tflite
INFO: STARTING!
INFO: Log parameter values verbosely: [0]
INFO: Graph: [BatchMatMul_FPE.tflite]
INFO: Loaded model BatchMatMul_FPE.tflite
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
INFO: The input model file size (MB): 0.0006
INFO: Initialized session in 1.486ms.
INFO: Running benchmark for at least 1 iterations and at least 0.5 seconds but terminate if exceeding 150 seconds.
INFO: count=1785957 first=3 curr=1 min=0 max=78 avg=0.193891 std=0

INFO: Running benchmark for at least 50 iterations and at least 1 seconds but terminate if exceeding 150 seconds.
INFO: count=3571192 first=1 curr=1 min=0 max=101 avg=0.193897 std=0

INFO: Inference timings in us: Init: 1486, First inference: 3, Warmup (avg): 0.193891, Inference (avg): 0.193897
INFO: Note: as the benchmark tool itself affects memory footprint, the following is only APPROXIMATE to the actual memory footprint of the model at runtime. Take the information at your discretion.
INFO: Memory footprint delta from the start of the tool (MB): init=3 overall=3
```

Can you verify if you uploaded the same model file or if somehow the latest code resolve this issue? Thanks. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61901">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61901">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.14.0

### Custom code

Yes

### OS platform and distribution

Ubuntu 18.04.6

### Mobile device

_No response_

### Python version

Python 3.8.3

### Bazel version

bazel 5.3.0

### GCC/compiler version

gcc 7.5.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?
Construct a malicious BatchMatMul operator model with a shape of 4x0x0x0. 
The `input_shape.Dims(i)`  variable may be equal to 0, leading to a division by zero error.
```cpp
// transpose_utils.cc
size_t Flatten(const RuntimeShape& input_shape,
               const RuntimeShape& output_shape, const TransposeParams& params,
               RuntimeShape* non_flatten_input_shape,
               RuntimeShape* non_flatten_output_shape,
               TransposeParams* non_flatten_params) {
  // Calculate the total size of non-flatten dimensions.
  int skip_dims_cnt = 0;
  size_t flat_size = input_shape.FlatSize();
  for (int i = 0; i < params.perm_count; ++i) {
    if (params.perm[i] == i) {
      flat_size /= input_shape.Dims(i);  // FPE
```
[BatchMatMul_FPE.zip](https://github.com/tensorflow/tensorflow/files/12655488/BatchMatMul_FPE.zip)


### Standalone code to reproduce the issue

```shell
When I use the benchmark tool for PoC validation, it causes the TensorFlow Lite inference process to be subjected to a DOS（coredump).


❯ ./benchmark_model --graph=../poc/BatchMatMul_FPE.tflite
INFO: STARTING!
INFO: Log parameter values verbosely: [0]
INFO: Graph: [../poc/BatchMatMul_FPE.tflite]
INFO: Loaded model ../poc/BatchMatMul_FPE.tflite
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
INFO: The input model file size (MB): 0.0006
INFO: Initialized session in 155.728ms.
INFO: Running benchmark for at least 1 iterations and at least 0.5 seconds but terminate if exceeding 150 seconds.
[1]    26298 floating point exception (core dumped)  ./benchmark_model --graph=../poc/BatchMatMul_FPE.tflite
```
```


### Relevant log output

_No response_