diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 1245ac1d2..469379bc9 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -1922,7 +1922,7 @@ class binary_reader bool is_optimized = get_ubjson_size_type(size_and_type); - if (size_and_type.first != string_t::npos) + if (is_optimized && size_and_type.first != string_t::npos) { if (size_and_type.second != 0) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 13c501f70..81fb82739 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10298,7 +10298,7 @@ class binary_reader bool is_optimized = get_ubjson_size_type(size_and_type); - if (size_and_type.first != string_t::npos) + if (is_optimized && size_and_type.first != string_t::npos) { if (size_and_type.second != 0) {