MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / verifyDumpPayload

Function verifyDumpPayload

src/cluster.cpp:5162–5182  ·  view source on GitHub ↗

Verify that the RDB version of the dump payload matches the one of this Redis * instance and that the checksum is ok. * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR * is returned. */

Source from the content-addressed store, hash-verified

5160 * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR
5161 * is returned. */
5162int verifyDumpPayload(unsigned char *p, size_t len) {
5163 unsigned char *footer;
5164 uint16_t rdbver;
5165 uint64_t crc;
5166
5167 /* At least 2 bytes of RDB version and 8 of CRC64 should be present. */
5168 if (len < 10) return C_ERR;
5169 footer = p+(len-10);
5170
5171 /* Verify RDB version */
5172 rdbver = (footer[1] << 8) | footer[0];
5173 if (rdbver > RDB_VERSION) return C_ERR;
5174
5175 if (cserver.skip_checksum_validation)
5176 return C_OK;
5177
5178 /* Verify CRC64 */
5179 crc = crc64(0,p,len-8);
5180 memrev64ifbe(&crc);
5181 return (memcmp(&crc,footer+2,8) == 0) ? C_OK : C_ERR;
5182}
5183
5184/* DUMP keyname
5185 * DUMP is actually not used by Redis Cluster but it is the obvious

Callers 2

mvccrestoreCommandFunction · 0.85
restoreCommandFunction · 0.85

Calls 1

crc64Function · 0.85

Tested by

no test coverage detected