From 3b99b98678077914bc8798f7cc535c0b007545fd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 18 Jan 2023 20:58:49 -0500 Subject: [PATCH] Truncate integer values before inserting them - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1383250353 --- src/Database/Definition/DbaDefinition.php | 4 ++++ 1 file changed, 4 insertions(+) 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]; }