| 88 | } |
| 89 | |
| 90 | std::unique_ptr<FlatBufferModel> FlatBufferModel::VerifyAndBuildFromFile( |
| 91 | const char* filename, TfLiteVerifier* extra_verifier, |
| 92 | ErrorReporter* error_reporter) { |
| 93 | error_reporter = ValidateErrorReporter(error_reporter); |
| 94 | |
| 95 | std::unique_ptr<FlatBufferModel> model; |
| 96 | auto allocation = GetAllocationFromFile(filename, /*mmap_file=*/true, |
| 97 | error_reporter, /*use_nnapi=*/true); |
| 98 | |
| 99 | flatbuffers::Verifier base_verifier( |
| 100 | reinterpret_cast<const uint8_t*>(allocation->base()), |
| 101 | allocation->bytes()); |
| 102 | if (!VerifyModelBuffer(base_verifier)) { |
| 103 | error_reporter->Report("The model is not a valid Flatbuffer file"); |
| 104 | return nullptr; |
| 105 | } |
| 106 | |
| 107 | if (extra_verifier && |
| 108 | !extra_verifier->Verify(static_cast<const char*>(allocation->base()), |
| 109 | allocation->bytes(), error_reporter)) { |
| 110 | return model; |
| 111 | } |
| 112 | model.reset(new FlatBufferModel(std::move(allocation), error_reporter)); |
| 113 | if (!model->initialized()) model.reset(); |
| 114 | return model; |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | std::unique_ptr<FlatBufferModel> FlatBufferModel::BuildFromBuffer( |
nothing calls this directly
no test coverage detected