diff options
author | Yuhong Zhang <yuhong.zhang@mongodb.com> | 2022-12-01 19:36:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-01 20:05:46 +0000 |
commit | f90b35cf6c25a223c2f96649ee74a8ee943c13c7 (patch) | |
tree | 8e955ae2e4eb206ce0accdf0549a28cf3a728ad7 /src | |
parent | 7382e1a20f9292ba19d20b69f7a317fd41b50900 (diff) | |
download | mongo-f90b35cf6c25a223c2f96649ee74a8ee943c13c7.tar.gz |
SERVER-71360 Avoid signed promotion on the value of the subtype before casting to BinDataType (cherry picked from commit d69c4bd59cff4c00d15421454dd6de2f90dfadb4)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/bson/bsonelementvalue.h | 3 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/values/value.h | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/mongo/bson/bsonelementvalue.h b/src/mongo/bson/bsonelementvalue.h index 1868242d6f8..474719e7a5b 100644 --- a/src/mongo/bson/bsonelementvalue.h +++ b/src/mongo/bson/bsonelementvalue.h @@ -95,9 +95,10 @@ public: * BinData (0x05) */ BSONBinData BinData() const { + uint8_t subtype = ConstDataView(value() + kCountBytes).read<LittleEndian<uint8_t>>(); return {value() + kCountBytes + kBinDataSubTypeBytes, ConstDataView(value()).read<LittleEndian<int>>(), - static_cast<BinDataType>(*(value() + kCountBytes))}; + static_cast<BinDataType>(subtype)}; } /** diff --git a/src/mongo/db/exec/sbe/values/value.h b/src/mongo/db/exec/sbe/values/value.h index 3d325a7e568..44d092d8186 100644 --- a/src/mongo/db/exec/sbe/values/value.h +++ b/src/mongo/db/exec/sbe/values/value.h @@ -1033,7 +1033,9 @@ inline size_t getBSONBinDataSize(TypeTags tag, Value val) { inline BinDataType getBSONBinDataSubtype(TypeTags tag, Value val) { invariant(tag == TypeTags::bsonBinData); - return static_cast<BinDataType>((getRawPointerView(val) + sizeof(uint32_t))[0]); + uint8_t subtype = + ConstDataView(getRawPointerView(val) + sizeof(uint32_t)).read<LittleEndian<uint8_t>>(); + return static_cast<BinDataType>(subtype); } inline uint8_t* getBSONBinData(TypeTags tag, Value val) { |