mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 05:37:04 +00:00
Fixed: Access violation and ASAN/UNSAN failures with sorted tables
https://github.com/google/flatbuffers/issues/5945
This commit is contained in:
@@ -1355,8 +1355,8 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||||||
// globals, making parsing thread-unsafe.
|
// globals, making parsing thread-unsafe.
|
||||||
// So for now, we use SimpleQsort above.
|
// So for now, we use SimpleQsort above.
|
||||||
// TODO: replace with something better, preferably not recursive.
|
// TODO: replace with something better, preferably not recursive.
|
||||||
static voffset_t offset = key->value.offset;
|
voffset_t offset = key->value.offset;
|
||||||
static BaseType ftype = key->value.type.base_type;
|
BaseType ftype = key->value.type.base_type;
|
||||||
|
|
||||||
if (type.struct_def->fixed) {
|
if (type.struct_def->fixed) {
|
||||||
auto v =
|
auto v =
|
||||||
@@ -1364,7 +1364,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||||||
SimpleQsort<uint8_t>(
|
SimpleQsort<uint8_t>(
|
||||||
v->Data(), v->Data() + v->size() * type.struct_def->bytesize,
|
v->Data(), v->Data() + v->size() * type.struct_def->bytesize,
|
||||||
type.struct_def->bytesize,
|
type.struct_def->bytesize,
|
||||||
[](const uint8_t *a, const uint8_t *b) -> bool {
|
[&](const uint8_t *a, const uint8_t *b) -> bool {
|
||||||
return CompareType(a + offset, b + offset, ftype);
|
return CompareType(a + offset, b + offset, ftype);
|
||||||
},
|
},
|
||||||
[&](uint8_t *a, uint8_t *b) {
|
[&](uint8_t *a, uint8_t *b) {
|
||||||
@@ -1381,7 +1381,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
|
|||||||
// can't be used to swap elements.
|
// can't be used to swap elements.
|
||||||
SimpleQsort<Offset<Table>>(
|
SimpleQsort<Offset<Table>>(
|
||||||
v->data(), v->data() + v->size(), 1,
|
v->data(), v->data() + v->size(), 1,
|
||||||
[](const Offset<Table> *_a, const Offset<Table> *_b) -> bool {
|
[&](const Offset<Table> *_a, const Offset<Table> *_b) -> bool {
|
||||||
// Indirect offset pointer to table pointer.
|
// Indirect offset pointer to table pointer.
|
||||||
auto a = reinterpret_cast<const uint8_t *>(_a) +
|
auto a = reinterpret_cast<const uint8_t *>(_a) +
|
||||||
ReadScalar<uoffset_t>(_a);
|
ReadScalar<uoffset_t>(_a);
|
||||||
|
|||||||
Reference in New Issue
Block a user