diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 81ea7f5138f..c79827c55b4 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -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 diff --git a/jstests/core/filemd5.js b/jstests/core/filemd5.js index a3733ca098f..3e61a5ab1f5 100644 --- a/jstests/core/filemd5.js +++ b/jstests/core/filemd5.js @@ -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); \ No newline at end of file +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"); +} diff --git a/src/mongo/util/md5.cpp b/src/mongo/util/md5.cpp index e4e5c2f44c4..062290bdbcf 100644 --- a/src/mongo/util/md5.cpp +++ b/src/mongo/util/md5.cpp @@ -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;