Truncate integer values before inserting them

- Address https://github.com/friendica/friendica/issues/12486#issuecomment-1383250353
This commit is contained in:
Hypolite Petovan 2023-01-18 20:58:49 -05:00
parent 594f738c6d
commit 3b99b98678

View file

@ -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];
}