mirror of
https://github.com/nlohmann/json.git
synced 2026-11-22 10:54:22 +00:00
Make parse_bson_internal's end-of-document top a copy, not a reference
Same issue as the CBOR and UBJSON/BJData readers: top aliased container_stack.back() and was read (top.is_object) right after container_stack.pop_back() ended its lifetime. A copy stays valid regardless of what happens to the stack; nothing here mutates the live entry, so no field needs to go through container_stack.back() directly. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+10
-6
No files matched your search
@@ -337,8 +337,10 @@ class binary_reader
|
|||||||
|
|
||||||
if (element_type == 0) // end of the innermost document
|
if (element_type == 0) // end of the innermost document
|
||||||
{
|
{
|
||||||
const container_frame& top = container_stack.back();
|
// a copy, not a reference: it must stay valid across the
|
||||||
const bool is_object = top.is_object;
|
// pop_back() below, which destroys the container_stack
|
||||||
|
// element it would otherwise alias
|
||||||
|
const container_frame top = container_stack.back();
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!check_bson_document_size(top.start_position, top.declared_size)))
|
if (JSON_HEDLEY_UNLIKELY(!check_bson_document_size(top.start_position, top.declared_size)))
|
||||||
{
|
{
|
||||||
@@ -346,7 +348,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
container_stack.pop_back();
|
container_stack.pop_back();
|
||||||
if (JSON_HEDLEY_UNLIKELY(is_object ? !sax->end_object() : !sax->end_array()))
|
if (JSON_HEDLEY_UNLIKELY(top.is_object ? !sax->end_object() : !sax->end_array()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11161,8 +11161,10 @@ class binary_reader
|
|||||||
|
|
||||||
if (element_type == 0) // end of the innermost document
|
if (element_type == 0) // end of the innermost document
|
||||||
{
|
{
|
||||||
const container_frame& top = container_stack.back();
|
// a copy, not a reference: it must stay valid across the
|
||||||
const bool is_object = top.is_object;
|
// pop_back() below, which destroys the container_stack
|
||||||
|
// element it would otherwise alias
|
||||||
|
const container_frame top = container_stack.back();
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!check_bson_document_size(top.start_position, top.declared_size)))
|
if (JSON_HEDLEY_UNLIKELY(!check_bson_document_size(top.start_position, top.declared_size)))
|
||||||
{
|
{
|
||||||
@@ -11170,7 +11172,7 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
container_stack.pop_back();
|
container_stack.pop_back();
|
||||||
if (JSON_HEDLEY_UNLIKELY(is_object ? !sax->end_object() : !sax->end_array()))
|
if (JSON_HEDLEY_UNLIKELY(top.is_object ? !sax->end_object() : !sax->end_array()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user