Skip to content

Commit 2118f5c

Browse files
author
Ole John Aske
committed
Bug#35155005 Buffers for holding a key of 'MAX_KEY_SIZE' are allocated too small
The #define MAX_KEY_SIZE_IN_WORDS 1023 are used multiple places where we need to define different kind of buffers for holding a tuple key. Some places we define this buffer as an array of Uint64's, probably due to a double word allignment were assumed to be more efficient when accessing the key buffer. As we right shifted-by-1 the MAX_KEY_SIZE_IN_WORDS when defining such Uint64 arrays, *without* adding +1 to compensate for the alignment truncation, the allocated Uint64 buffer ended up being a 'word' too small to buffer a full MAX_KEY. These Uint64 buffers where used for storing a key to calculate a hash key - md5_hash() used to take a Uint64* aligned argument for the value to be hashed. This was changed by patch for Bug#35180841 Remove requirement for md5_hash() input to be 8-byte aligned Thus we can now define these buffers as Uint32[] instead. Patch change these buffer definitions accordingly. Change-Id: If5356bae4a3e997fdb09caa89fd3c3626b782d56
1 parent 7246364 commit 2118f5c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

storage/ndb/plugin/ha_ndbcluster.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7599,7 +7599,7 @@ NdbTransaction *ha_ndbcluster::start_transaction_row(
75997599

76007600
Ndb *ndb = m_thd_ndb->ndb;
76017601

7602-
Uint64 tmp[(MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY) >> 1];
7602+
Uint32 tmp[MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY];
76037603
char *buf = (char *)&tmp[0];
76047604
trans =
76057605
ndb->startTransaction(ndb_record, (const char *)record, buf, sizeof(tmp));
@@ -7627,7 +7627,7 @@ NdbTransaction *ha_ndbcluster::start_transaction_key(uint index_num,
76277627
Ndb *ndb = m_thd_ndb->ndb;
76287628
const NdbRecord *key_rec = m_index[index_num].ndb_unique_record_key;
76297629

7630-
Uint64 tmp[(MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY) >> 1];
7630+
Uint32 tmp[MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY];
76317631
char *buf = (char *)&tmp[0];
76327632
trans =
76337633
ndb->startTransaction(key_rec, (const char *)key_data, buf, sizeof(tmp));
@@ -14775,7 +14775,7 @@ uint32 ha_ndbcluster::calculate_key_hash_value(Field **field_array) {
1477514775
struct Ndb::Key_part_ptr *key_data_ptr = &key_data[0];
1477614776
Uint32 i = 0;
1477714777
int ret_val;
14778-
Uint64 tmp[(MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY) >> 1];
14778+
Uint32 tmp[MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY];
1477914779
void *buf = (void *)&tmp[0];
1478014780
DBUG_TRACE;
1478114781

storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17641,23 +17641,23 @@ Uint32
1764117641
Dblqh::readPrimaryKeys(Uint32 opPtrI, Uint32 *dst, bool xfrm_hash)
1764217642
{
1764317643
TcConnectionrecPtr regTcPtr;
17644-
Uint64 Tmp[MAX_KEY_SIZE_IN_WORDS >> 1];
17644+
Uint32 Tmp[MAX_KEY_SIZE_IN_WORDS];
1764517645

1764617646
jamEntry();
1764717647
regTcPtr.i = opPtrI;
1764817648
ndbrequire(tcConnect_pool.getValidPtr(regTcPtr));
1764917649

1765017650
const Uint32 tableId = regTcPtr.p->tableref;
1765117651
const Uint32 keyLen = regTcPtr.p->primKeyLen;
17652-
Uint32 *buf = xfrm_hash ? (Uint32*)Tmp : dst;
17652+
Uint32 *buf = xfrm_hash ? Tmp : dst;
1765317653

1765417654
copy(buf, regTcPtr.p->keyInfoIVal);
1765517655

1765617656
if (xfrm_hash)
1765717657
{
1765817658
jam();
1765917659
Uint32 keyPartLen[MAX_ATTRIBUTES_IN_INDEX];
17660-
return xfrm_key_hash(tableId, (Uint32*)Tmp, dst, ~0, keyPartLen);
17660+
return xfrm_key_hash(tableId, Tmp, dst, ~0, keyPartLen);
1766117661
}
1766217662
return keyLen;
1766317663
}

0 commit comments

Comments
 (0)