SERVER-119317 Improve object lifecycle of MD5 hash state (#47996)

GitOrigin-RevId: 28927c60881a488fcbc5fd4d925b410f33258827
This commit is contained in:
Spencer Jackson 2026-02-18 14:54:26 -08:00 committed by MongoDB Bot
parent 47531c9281
commit 05009bb976
3 changed files with 27 additions and 1 deletions

View File

@ -23,6 +23,8 @@ last-continuous:
all:
- test_file: jstests/core/index/elemmatch_index.js
ticket: SERVER-108945
- test_file: jstests/core/filemd5.js
ticket: SERVER-119317
- test_file: jstests/core/json_schema/json_schema.js
ticket: SERVER-98676
- test_file: jstests/core/query/explain/explain_plan_cache.js
@ -902,6 +904,8 @@ last-lts:
all:
- test_file: jstests/core/index/elemmatch_index.js
ticket: SERVER-108945
- test_file: jstests/core/filemd5.js
ticket: SERVER-119317
- test_file: jstests/core/json_schema/json_schema.js
ticket: SERVER-98676
- test_file: jstests/core/query/explain/explain_plan_cache.js

View File

@ -20,4 +20,24 @@ assert.commandFailedWithCode(db.runCommand({filemd5: 1, root: "fs", partialOk: 1
assert.commandWorked(db.fs.chunks.insert({files_id: 2, n: 0}));
assert.commandFailedWithCode(db.runCommand({filemd5: 2, root: "fs"}), 50848);
assert.commandWorked(db.fs.chunks.update({files_id: 2, n: 0}, {$set: {data: 5}}));
assert.commandFailedWithCode(db.runCommand({filemd5: 2, root: "fs"}), 50849);
assert.commandFailedWithCode(db.runCommand({filemd5: 2, root: "fs"}), 50849);
{
const result = assert.commandWorked(
db.runCommand({
filemd5: ObjectId("000000000000000000000000"),
root: "fs",
partialOk: true,
}),
);
assert(result.md5state !== undefined, "Expected md5state in filemd5 response with partialOk: true");
const hex = result.md5state.hex();
const totalBytes = hex.length / 2;
assert.gt(totalBytes, 72, "md5state expected to be larger than 72 bytes");
const checkFromByte = 72;
const paddingHex = hex.substring(checkFromByte * 2);
const allZeros = "0".repeat(paddingHex.length);
assert.eq(paddingHex, allZeros, "md5state expected to be zero padded");
}

View File

@ -309,6 +309,8 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) {
}
void md5_init(md5_state_t* pms) {
memset(pms, 0, sizeof(md5_state_t));
pms->count[0] = pms->count[1] = 0;
pms->abcd[0] = 0x67452301;
pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;