Skip to content

Commit 0b4050a

Browse files
authored
verify the description of flatbuffers, test=develop (#5064)
1 parent db6d2da commit 0b4050a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lite/model_parser/base/io.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ class Buffer {
5151

5252
void CopyDataFrom(const Buffer& other);
5353

54-
Buffer(Buffer&& other) { raw_ = other.Release(); }
54+
Buffer(Buffer&& other) {
55+
raw_ = other.Release();
56+
size_ = other.size();
57+
}
5558
Buffer& operator=(Buffer&& other) {
5659
raw_ = other.Release();
60+
size_ = other.size();
5761
return *this;
5862
}
5963

lite/model_parser/flatbuffers/param_desc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ParamDescView : public ParamDescReadAPI {
3434
public:
3535
explicit ParamDescView(model_parser::Buffer* buf) {
3636
CHECK(buf) << "The pointer in buf can not be nullptr";
37+
flatbuffers::Verifier verifier(static_cast<const uint8_t*>(buf->data()),
38+
buf->size());
39+
CHECK(verifier.VerifyBuffer<paddle::lite::fbs::proto::ParamDesc>(nullptr))
40+
<< "Param verification failed.";
3741
desc_ =
3842
flatbuffers::GetRoot<paddle::lite::fbs::proto::ParamDesc>(buf->data());
3943
Init();
@@ -92,6 +96,11 @@ class CombinedParamsDescView : public CombinedParamsDescReadAPI {
9296
}
9397

9498
void InitParams() {
99+
flatbuffers::Verifier verifier(static_cast<const uint8_t*>(buf_.data()),
100+
buf_.size());
101+
CHECK(verifier.VerifyBuffer<paddle::lite::fbs::proto::CombinedParamsDesc>(
102+
nullptr))
103+
<< "CombinedParamsDesc verification failed.";
95104
desc_ = proto::GetCombinedParamsDesc(buf_.data());
96105
CHECK(desc_);
97106
CHECK(desc_->params());

lite/model_parser/flatbuffers/program_desc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class ProgramDescView : public ProgramDescAPI {
4444
}
4545

4646
void InitProgramDesc() {
47+
flatbuffers::Verifier verifier(static_cast<const uint8_t*>(buf_.data()),
48+
buf_.size());
49+
CHECK(verifier.VerifyBuffer<paddle::lite::fbs::proto::ProgramDesc>(nullptr))
50+
<< "Program verification failed.";
4751
desc_ = proto::GetProgramDesc(buf_.data());
4852
blocks_.resize(desc_->blocks()->size());
4953
for (size_t idx = 0; idx < BlocksSize(); ++idx) {

0 commit comments

Comments
 (0)