Skip to content

Commit 5fb5dc0

Browse files
author
Ole John Aske
committed
Bug#35155005 Buffers for holding a key of 'MAX_KEY_SIZE' are allocated too small
NdbIndexScanOperation::getDistKeyFromRange() allocated the tmp[] buffer as a working area for Ndb::computeHash() to xfrm the key into if need. The buffer was allocated with the correct size for transforming a key of NDB_MAX_KEY_SIZE, multiplied with the MAX_XFRM_MULTIPLY. However, the same buffer was also used in case a key column needed shrink_varchar()-reformat (and copy) of the key. Thus, possibly leaving a too small buffer remaining for the hash-xfrm of the key in ::computeHash() Patch divide the buffer usage into two seperate buffers: - Uint32 xfrmbuf[ MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY ] Used only as argument to ::computeHash() - Uint32 shrinkbuf[ MAX_KEY_SIZE_IN_WORDS ] Used in case we need to shrink_varchar()-copy the key. Change-Id: I9589269ce0e2dc084f262817f0708797032a9e84
1 parent 1eda52f commit 5fb5dc0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

storage/ndb/src/ndbapi/NdbScanOperation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2003, 2023, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -762,11 +762,11 @@ NdbIndexScanOperation::getDistKeyFromRange(const NdbRecord *key_record,
762762
const char *row,
763763
Uint32* distKey)
764764
{
765-
const Uint32 MaxKeySizeInLongWords= (NDB_MAX_KEY_SIZE + 7) / 8;
766-
// Note: xfrm:ed key can/will be bigger than MaxKeySizeInLongWords
767-
Uint64 tmp[ MaxKeySizeInLongWords * MAX_XFRM_MULTIPLY ];
768-
char* tmpshrink = (char*)tmp;
769-
Uint32 tmplen = (Uint32)sizeof(tmp);
765+
// Note: xfrm:ed key can/will be bigger than MAX_KEY_SIZE_IN_WORDS
766+
Uint32 xfrmbuf[MAX_KEY_SIZE_IN_WORDS * MAX_XFRM_MULTIPLY];
767+
char shrinkbuf[NDB_MAX_KEY_SIZE];
768+
char* tmpshrink = shrinkbuf;
769+
Uint32 tmplen = (Uint32)sizeof(shrinkbuf);
770770

771771
/* This can't work for User Defined partitioning */
772772
assert(key_record->table->m_fragmentType !=
@@ -811,7 +811,7 @@ NdbIndexScanOperation::getDistKeyFromRange(const NdbRecord *key_record,
811811

812812
Uint32 hashValue;
813813
int ret = Ndb::computeHash(&hashValue, result_record->table,
814-
ptrs, tmpshrink, tmplen);
814+
ptrs, xfrmbuf, sizeof(xfrmbuf));
815815
if (ret == 0)
816816
{
817817
*distKey = hashValue;

0 commit comments

Comments
 (0)