Skip to content

Commit

Permalink
[luci/import] Revise importVerifyModule (#14126)
Browse files Browse the repository at this point in the history
This will revise importVerifyModule to verify only when file size is
less than 2G.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored Sep 30, 2024
1 parent 9d213f6 commit ea4b83c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions compiler/luci/import/src/ImporterEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
namespace luci
{

namespace
{

// limitation of current flatbuffers file size
inline constexpr uint64_t FLATBUFFERS_SIZE_MAX = 2147483648UL; // 2GB

} // namespace

std::unique_ptr<Module> ImporterEx::importVerifyModule(const std::string &input_path) const
{
foder::FileLoader file_loader{input_path};
Expand All @@ -43,11 +51,14 @@ std::unique_ptr<Module> ImporterEx::importVerifyModule(const std::string &input_
auto data_data = reinterpret_cast<uint8_t *>(model_data.data());
auto data_size = model_data.size();

flatbuffers::Verifier verifier{data_data, data_size};
if (!circle::VerifyModelBuffer(verifier))
if (data_size < FLATBUFFERS_SIZE_MAX)
{
std::cerr << "ERROR: Invalid input file '" << input_path << "'" << std::endl;
return nullptr;
flatbuffers::Verifier verifier{data_data, data_size};
if (!circle::VerifyModelBuffer(verifier))
{
std::cerr << "ERROR: Invalid input file '" << input_path << "'" << std::endl;
return nullptr;
}
}

Importer importer(_source);
Expand Down

0 comments on commit ea4b83c

Please sign in to comment.