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

GitOrigin-RevId: 0fdd1677b1724f69239befcac04f12b9a605489d
This commit is contained in:
Spencer Jackson 2026-03-19 14:57:28 -07:00 committed by MongoDB Bot
parent 65254fb212
commit 6184790fd2
3 changed files with 28 additions and 1 deletions

View File

@ -25,6 +25,8 @@ last-continuous:
ticket: SERVER-108945
- test_file: jstests/core/json_schema/json_schema.js
ticket: SERVER-98676
- test_file: jstests/core/filemd5.js
ticket: SERVER-119317
- test_file: jstests/sharding/analyze_shard_key/analyze_shard_key_cmd_validation.js
ticket: SERVER-95869
- test_file: jstests/change_streams/change_streams_dynamic_match_expressions.js
@ -664,6 +666,8 @@ last-lts:
ticket: SERVER-108945
- test_file: jstests/core/json_schema/json_schema.js
ticket: SERVER-98676
- test_file: jstests/core/filemd5.js
ticket: SERVER-119317
- test_file: jstests/sharding/analyze_shard_key/analyze_shard_key_cmd_validation.js
ticket: SERVER-95869
- test_file: jstests/change_streams/change_streams_dynamic_match_expressions.js

View File

@ -24,4 +24,25 @@ 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);
}());
{
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;