diff options
author | Gabriel Russell <gabriel.russell@mongodb.com> | 2019-09-10 20:42:39 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-10 20:42:39 +0000 |
commit | 3f6ba750fc8374968c3c06e31c67ac2839e9a736 (patch) | |
tree | 2f9d1ab2ae09846b3c4ad82bf8862229c29fc392 /src/mongo/bson/bsonelement.h | |
parent | dbcd60ce23a3f151e689c796b266b752bebb4764 (diff) | |
download | mongo-3f6ba750fc8374968c3c06e31c67ac2839e9a736.tar.gz |
SERVER-41994 correctly create and show type 2 binary elements
Diffstat (limited to 'src/mongo/bson/bsonelement.h')
-rw-r--r-- | src/mongo/bson/bsonelement.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h index 892be6df831..d7733b7966a 100644 --- a/src/mongo/bson/bsonelement.h +++ b/src/mongo/bson/bsonelement.h @@ -494,9 +494,18 @@ public: if (binDataType() != ByteArrayDeprecated) { return binData(len); } else { - // Skip extra size - len = valuestrsize() - 4; - return value() + 5 + 4; + // Because, for some time, the shell has incorrectly created type 2 binary objects + // without the extra length, we try to identify if this object does or doesn't start + // with a length and skip past it when its present. See SERVER-41994 + if (valuestrsize() >= 4 && + ConstDataView(value() + 5).read<LittleEndian<int>>() == valuestrsize() - 4) { + // Skip extra size + len = valuestrsize() - 4; + return value() + 5 + 4; + } else { + len = valuestrsize(); + return value() + 5; + } } } |