From da8d5f501592274e5814cbcd7af36450c57f1823 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 May 2021 19:44:24 +0000 Subject: [PATCH] Issue 9926: Limit the length of data to store in the apcontact table --- src/Database/DBStructure.php | 4 ++++ src/Model/APContact.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 82e405942..04ba956bc 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -241,6 +241,10 @@ class DBStructure // Assign all field that are present in the table foreach ($fieldnames as $field) { if (isset($data[$field])) { + // Limit the length of varchar, varbinary, char and binrary fields + if (is_string($data[$field]) && preg_match("/[char|binary]\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) { + $data[$field] = mb_substr($data[$field], 0, $result[1]); + } $fields[$field] = $data[$field]; } } diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 7a63e413c..28bb31c83 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -26,6 +26,7 @@ use Friendica\Core\Cache\Duration; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Network\Probe; use Friendica\Protocol\ActivityNamespace; @@ -349,6 +350,9 @@ class APContact DBA::delete('apcontact', ['url' => $url]); } + // Limit the length on incoming fields + $apcontact = DBStructure::getFieldsForTable('apcontact', $apcontact); + if (DBA::exists('apcontact', ['url' => $apcontact['url']])) { DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]); } else {