mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 22:52:17 +00:00
Fix misaligned nested buffers (#4785)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
3e3c770c4e
commit
b752e4a9bb
@@ -997,6 +997,9 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
|
|||||||
flexbuffers::BUILDER_FLAG_SHARE_ALL);
|
flexbuffers::BUILDER_FLAG_SHARE_ALL);
|
||||||
ECHECK(parser->ParseFlexBufferValue(&builder));
|
ECHECK(parser->ParseFlexBufferValue(&builder));
|
||||||
builder.Finish();
|
builder.Finish();
|
||||||
|
// Force alignment for nested flexbuffer
|
||||||
|
parser->builder_.ForceVectorAlignment(builder.GetSize(), sizeof(uint8_t),
|
||||||
|
sizeof(largest_scalar_t));
|
||||||
auto off = parser->builder_.CreateVector(builder.GetBuffer());
|
auto off = parser->builder_.CreateVector(builder.GetBuffer());
|
||||||
val.constant = NumToString(off.o);
|
val.constant = NumToString(off.o);
|
||||||
} else if (field->nested_flatbuffer) {
|
} else if (field->nested_flatbuffer) {
|
||||||
@@ -1207,6 +1210,10 @@ CheckedError Parser::ParseNestedFlatbuffer(Value &val, FieldDef *field,
|
|||||||
if (!nested_parser.Parse(substring.c_str(), nullptr, nullptr)) {
|
if (!nested_parser.Parse(substring.c_str(), nullptr, nullptr)) {
|
||||||
ECHECK(Error(nested_parser.error_));
|
ECHECK(Error(nested_parser.error_));
|
||||||
}
|
}
|
||||||
|
// Force alignment for nested flatbuffer
|
||||||
|
builder_.ForceVectorAlignment(nested_parser.builder_.GetSize(), sizeof(uint8_t),
|
||||||
|
nested_parser.builder_.GetBufferMinAlignment());
|
||||||
|
|
||||||
auto off = builder_.CreateVector(nested_parser.builder_.GetBufferPointer(),
|
auto off = builder_.CreateVector(nested_parser.builder_.GetBufferPointer(),
|
||||||
nested_parser.builder_.GetSize());
|
nested_parser.builder_.GetSize());
|
||||||
val.constant = NumToString(off.o);
|
val.constant = NumToString(off.o);
|
||||||
|
|||||||
Reference in New Issue
Block a user