summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2016-07-27 23:23:43 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2016-08-02 19:22:51 -0400
commit2743e906fef318763e753a67967d503b37fcdd07 (patch)
tree38d98eb7843b249ef5bdb9dea2f8d707726a2acb /src/mongo/db/index
parent85b75d09a5812ff7a22d96b3f36596abe5eedb81 (diff)
downloadmongo-2743e906fef318763e753a67967d503b37fcdd07.tar.gz
SERVER-25075 Limit BSONObj buffer size used by 2dsphere index.
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/s2_common.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/mongo/db/index/s2_common.cpp b/src/mongo/db/index/s2_common.cpp
index d15582f1f7a..3cce81416db 100644
--- a/src/mongo/db/index/s2_common.cpp
+++ b/src/mongo/db/index/s2_common.cpp
@@ -89,12 +89,21 @@ BSONObj S2CellIdToIndexKey(const S2CellId& cellId, S2IndexVersion indexVersion)
// more than once face, individual intervals will
// never cross that threshold. Thus, scans will still
// produce the same results.
- BSONObjBuilder b;
if (indexVersion >= S2_INDEX_VERSION_3) {
+ // The size of an index BSONObj in S2 index version 3 is 15 bytes.
+ // total size (4 bytes) | type code 0x12 (1) | field name "" 0x00 (1) |
+ // long long cell id (8) | EOO (1)
+ BSONObjBuilder b(15);
b.append("", static_cast<long long>(cellId.id()));
- } else {
- b.append("", cellId.ToString());
+ return b.obj();
}
- return b.obj();
+
+ // The size of an index BSONObj in older versions is 10 ~ 40 bytes.
+ // total size (4 bytes) | type code 0x12 (1) | field name "" 0x00 (1) |
+ // cell id string (2 ~ 32) 0x00 (1) | EOO (1)
+ BSONObjBuilder b;
+ b.append("", cellId.ToString());
+ // Return a copy so its buffer size fits the object size.
+ return b.obj().copy();
}
} // namespace mongo