summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r--src/mongo/bson/bsonelement.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index c72e61eb888..940589d193b 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -213,7 +213,11 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
BinDataType type = static_cast<BinDataType>(reader.readAndAdvance<uint8_t>());
s << "{ \"$binary\" : \"";
- base64::encode(s, reader.view(), len);
+ if (type == ByteArrayDeprecated && len >= 4) {
+ base64::encode(s, reader.view() + 4, len - 4);
+ } else {
+ base64::encode(s, reader.view(), len);
+ }
auto origFill = s.fill();
auto origFmtF = s.flags();