summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-12-10 09:17:04 -0100
committerMaxence Lange <maxence@artificial-owl.com>2018-12-10 09:17:04 -0100
commita9cc7909508e173e268c63d39a1bc20e0c8d59da (patch)
tree19e36c71c6d771bfe2396194b56369e950b9452c /lib
parentfd40dc73a65f24b3065c7c5182ec28a21403f447 (diff)
check size of source entry before insert in database
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/CacheActorsRequest.php7
-rw-r--r--lib/Db/CoreRequestBuilder.php3
-rw-r--r--lib/Db/NotesRequest.php7
3 files changed, 15 insertions, 2 deletions
diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php
index 7a3f0ff2..8698b29f 100644
--- a/lib/Db/CacheActorsRequest.php
+++ b/lib/Db/CacheActorsRequest.php
@@ -66,6 +66,11 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
* @return int
*/
public function save(Person $actor): int {
+ $source = $actor->getSource();
+ if (sizeof($source) >= CoreRequestBuilder::SOURCE_LENGTH) {
+ $source = 'too_big';
+ }
+
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
@@ -84,7 +89,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
- ->setValue('source', $qb->createNamedParameter($actor->getSource()))
+ ->setValue('source', $qb->createNamedParameter($source))
->setValue('details', $qb->createNamedParameter(json_encode($actor->getDetails())))
->setValue(
'creation',
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index 7176ed8c..8f594ddd 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -64,6 +64,9 @@ class CoreRequestBuilder {
const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
+ const SOURCE_LENGTH = 10000;
+
+
/** @var IDBConnection */
protected $dbConnection;
diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php
index 9e687e25..10b155e7 100644
--- a/lib/Db/NotesRequest.php
+++ b/lib/Db/NotesRequest.php
@@ -68,6 +68,11 @@ class NotesRequest extends NotesRequestBuilder {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
+ $source = $note->getSource();
+ if (sizeof($source) >= CoreRequestBuilder::SOURCE_LENGTH) {
+ $source = 'too_big';
+ }
+
$qb = $this->getNotesInsertSql();
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
->setValue('type', $qb->createNamedParameter($note->getType()))
@@ -95,7 +100,7 @@ class NotesRequest extends NotesRequestBuilder {
)
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
- ->setValue('source', $qb->createNamedParameter($note->getSource()))
+ ->setValue('source', $qb->createNamedParameter($source))
->setValue(
'instances', $qb->createNamedParameter(
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)