From: Hypolite Petovan Date: Thu, 19 Jan 2023 01:58:49 +0000 (-0500) Subject: Truncate integer values before inserting them X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3b99b98678077914bc8798f7cc535c0b007545fd;p=friendica.git Truncate integer values before inserting them - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1383250353 --- diff --git a/src/Database/Definition/DbaDefinition.php b/src/Database/Definition/DbaDefinition.php index b65a7d30ed..1e597bd64b 100644 --- a/src/Database/Definition/DbaDefinition.php +++ b/src/Database/Definition/DbaDefinition.php @@ -87,6 +87,10 @@ class DbaDefinition $data[$field] = mb_substr($data[$field], 0, $result[1]); } elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) { $data[$field] = substr($data[$field], 0, $result[1]); + } elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') { + $data[$field] = min(max((int)$data[$field], -2147483648), 2147483647); + } elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int unsigned') { + $data[$field] = min(max((int)$data[$field], 0), 4294967295); } $fields[$field] = $data[$field]; }