summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/key_string.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/storage/key_string.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/storage/key_string.cpp')
-rw-r--r--src/mongo/db/storage/key_string.cpp40
1 files changed, 8 insertions, 32 deletions
diff --git a/src/mongo/db/storage/key_string.cpp b/src/mongo/db/storage/key_string.cpp
index 1284e5e4e44..908bd51908a 100644
--- a/src/mongo/db/storage/key_string.cpp
+++ b/src/mongo/db/storage/key_string.cpp
@@ -281,7 +281,7 @@ StringData readCStringWithNuls(BufReader* reader, std::string* scratch) {
return initial; // Don't alloc or copy for simple case with no NUL bytes.
scratch->append(initial.rawData(), initial.size());
- while (reader->remaining() && reader->peek<unsigned char>() == 0xFF) {
+ while (reader->peek<unsigned char>() == 0xFF) {
// Each time we enter this loop it means we hit a NUL byte encoded as "\x00\xFF".
*scratch += '\0';
reader->skip(1);
@@ -2598,15 +2598,10 @@ BSONObj toBson(StringData data, Ordering ord, const TypeBits& typeBits) {
RecordId decodeRecordIdLongAtEnd(const void* bufferRaw, size_t bufSize) {
const unsigned char* buffer = static_cast<const unsigned char*>(bufferRaw);
- keyStringAssert(8273006,
- fmt::format("Input too short to encode RecordId. bufSize: {}", bufSize),
- bufSize >= 2); // smallest possible encoding of a RecordId.
+ invariant(bufSize >= 2); // smallest possible encoding of a RecordId.
const unsigned char lastByte = *(buffer + bufSize - 1);
const size_t ridSize = 2 + (lastByte & 0x7); // stored in low 3 bits.
- keyStringAssert(
- 8273001,
- fmt::format("Encoded RecordId size is too big. bufSize: {}, ridSize: {}", bufSize, ridSize),
- bufSize >= ridSize);
+ invariant(bufSize >= ridSize);
const unsigned char* firstBytePtr = buffer + bufSize - ridSize;
BufReader reader(firstBytePtr, ridSize);
return decodeRecordIdLong(&reader);
@@ -2661,12 +2656,7 @@ RecordId decodeRecordIdLong(BufReader* reader) {
}
const uint8_t lastByte = readType<uint8_t>(reader, false);
- keyStringAssert(8273000,
- fmt::format("Number of extra bytes for RecordId is not encoded correctly. Low "
- "3 bits of lastByte: {}, high 3 bits of firstByte: {}",
- lastByte & 0x7,
- numExtraBytes),
- (lastByte & 0x7) == numExtraBytes);
+ invariant((lastByte & 0x7) == numExtraBytes);
repr = (repr << 5) | (lastByte >> 3); // fold in high 5 bits of last byte
return RecordId(repr);
}
@@ -2686,21 +2676,12 @@ RecordId decodeRecordIdStrAtEnd(const void* bufferRaw, size_t bufSize) {
// Continuation bytes
size_t sizeByteId = 0;
for (; buffer[bufSize - 1 - sizeByteId] & 0x80; sizeByteId++) {
- keyStringAssert(
- 8273002,
- fmt::format("size bytes too long. bufSize: {}, sizeByteId: {}", bufSize, sizeByteId),
- bufSize > sizeByteId + 1 /* this is cont, so next byte must be within buffer */);
- keyStringAssert(
- 8273003,
- fmt::format("size bytes longer than maximum allowed bytes. sizeByteId: {}", sizeByteId),
- sizeByteId < kRecordIdStrEncodedSizeMaxBytes);
+ invariant(bufSize >= sizeByteId + 1 /* non-cont byte */);
+ invariant(sizeByteId < kRecordIdStrEncodedSizeMaxBytes);
sizes[sizeByteId] = buffer[bufSize - 1 - sizeByteId] & 0x7F;
}
// Last (non-continuation) byte
- keyStringAssert(
- 8273004,
- fmt::format("size bytes longer than maximum allowed bytes. sizeByteId: {}", sizeByteId),
- sizeByteId < kRecordIdStrEncodedSizeMaxBytes);
+ invariant(sizeByteId < kRecordIdStrEncodedSizeMaxBytes);
sizes[sizeByteId] = buffer[bufSize - 1 - sizeByteId];
const size_t numSegments = sizeByteId + 1;
@@ -2710,12 +2691,7 @@ RecordId decodeRecordIdStrAtEnd(const void* bufferRaw, size_t bufSize) {
}
ridSize += static_cast<size_t>(sizes[sizeByteId]) << ((numSegments - sizeByteId - 1) * 7);
- keyStringAssert(8273005,
- fmt::format("RecordId too long. bufSize: {}, ridSize: {}, numSegments: {}",
- bufSize,
- ridSize,
- numSegments),
- bufSize >= ridSize + numSegments);
+ invariant(bufSize >= ridSize + numSegments);
return RecordId(reinterpret_cast<const char*>(buffer) + (bufSize - ridSize - numSegments),
ridSize);