]> git.mxchange.org Git - friendica.git/commitdiff
Truncate integer values before inserting them
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 19 Jan 2023 01:58:49 +0000 (20:58 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 19 Jan 2023 01:58:49 +0000 (20:58 -0500)
- Address https://github.com/friendica/friendica/issues/12486#issuecomment-1383250353

src/Database/Definition/DbaDefinition.php

index b65a7d30eda8519a03ed3095387a295c028e067e..1e597bd64bc886c80ad20fa7ca8812a0974e6db0 100644 (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];
                        }