From 340d1a3447cf821924aaaeefa5e6aef0fcdbf0c0 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 19 Apr 2017 17:41:53 -0700 Subject: [PATCH] Fix FlexBuffers writing incomplete length for 64-bit vectors. --- include/flatbuffers/flexbuffers.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index da0f18b4b..2c7a25ec7 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -1088,8 +1088,8 @@ class Builder FLATBUFFERS_FINAL_CLASS { reinterpret_cast(val) + size); } - // For values T >= byte_width template void Write(T val, size_t byte_width) { + assert(sizeof(T) >= byte_width); val = flatbuffers::EndianScalar(val); WriteBytes(&val, byte_width); } @@ -1239,7 +1239,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { // TODO: instead of asserting, could write vector with larger elements // instead, though that would be wasteful. assert(WidthU(len) <= bit_width); - if (!fixed) Write(len, byte_width); + if (!fixed) Write(len, byte_width); auto vloc = buf_.size(); for (size_t i = 0; i < len; i++) Write(elems[i], byte_width); stack_.push_back(Value(static_cast(vloc), @@ -1281,9 +1281,9 @@ class Builder FLATBUFFERS_FINAL_CLASS { // Write vector. First the keys width/offset if available, and size. if (keys) { WriteOffset(keys->u_, byte_width); - Write(1U << keys->min_bit_width_, byte_width); + Write(1U << keys->min_bit_width_, byte_width); } - if (!fixed) Write(vec_len, byte_width); + if (!fixed) Write(vec_len, byte_width); // Then the actual data. auto vloc = buf_.size(); for (size_t i = start; i < stack_.size(); i += step) {