You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-07 03:22:57 +03:00
MCOL-477 Add validation to alter autoincrement
If the data isn't validated and someone gives bad input it could cause corruption. This validates the input.
This commit is contained in:
@@ -1854,6 +1854,68 @@ void AlterTableProcessor::tableComment(uint32_t sessionID, execplan::CalpontSyst
|
||||
throw std::runtime_error("Table does not have an autoincrement column");
|
||||
}
|
||||
int32_t oid = systemCatalogPtr->autoColumOid(tableName);
|
||||
|
||||
CalpontSystemCatalog::ColType type = systemCatalogPtr->colType(oid);
|
||||
|
||||
bool validated = true;
|
||||
bool negative = false;
|
||||
|
||||
switch (type.colDataType)
|
||||
{
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
if (static_cast<int64_t>(nextVal) > MAX_BIGINT)
|
||||
validated = false;
|
||||
if (static_cast<int64_t>(nextVal) < 1)
|
||||
negative = true;
|
||||
break;
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
if (nextVal > MAX_UBIGINT)
|
||||
validated = false;
|
||||
break;
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
if (static_cast<int64_t>(nextVal) > MAX_INT)
|
||||
validated = false;
|
||||
if (static_cast<int64_t>(nextVal) < 1)
|
||||
negative = true;
|
||||
break;
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
if (nextVal > MAX_UINT)
|
||||
validated = false;
|
||||
break;
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
if (static_cast<int64_t>(nextVal) > MAX_SMALLINT)
|
||||
validated = false;
|
||||
if (static_cast<int64_t>(nextVal) < 1)
|
||||
negative = true;
|
||||
break;
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
if (nextVal > MAX_USMALLINT)
|
||||
validated = false;
|
||||
break;
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
if (static_cast<int64_t>(nextVal) > MAX_TINYINT)
|
||||
validated = false;
|
||||
if (static_cast<int64_t>(nextVal) < 1)
|
||||
negative = true;
|
||||
break;
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
if (nextVal > MAX_UTINYINT)
|
||||
validated = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!validated)
|
||||
{
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_INVALID_START_VALUE));
|
||||
}
|
||||
if (negative)
|
||||
{
|
||||
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_NEGATIVE_STARTVALUE));
|
||||
}
|
||||
|
||||
fDbrm->resetAISequence(oid, nextVal);
|
||||
ByteStream bs;
|
||||
bs.restart();
|
||||
|
Reference in New Issue
Block a user