Matmarex has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75324


Change subject: Bail when JSON length exceeds database limits
......................................................................

Bail when JSON length exceeds database limits

This might not be necessary on non-MySQL databases, but I'm sure that
at least their limits aren't lower than MySQL's, so let's stay on the
safe side.

Bug: 51740
Change-Id: I9c7115a951f126844bc70755bff12e8cd5fc2be1
---
M TemplateData.i18n.php
M TemplateDataBlob.php
M tests/TemplateDataBlobTest.php
3 files changed, 18 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData 
refs/changes/24/75324/1

diff --git a/TemplateData.i18n.php b/TemplateData.i18n.php
index 34a4605..b016ec9 100644
--- a/TemplateData.i18n.php
+++ b/TemplateData.i18n.php
@@ -23,6 +23,7 @@
        'templatedata-invalid-missing' => 'Required property "$1" not found.',
        'templatedata-invalid-unknown' => 'Unexpected property "$1".',
        'templatedata-invalid-value' => 'Invalid value for property "$1".',
+       'templatedata-invalid-length' => 'Data too long to save ($1 bytes, 
limit is $2)',
 );
 
 /** Message documentation (Message documentation)
@@ -61,6 +62,9 @@
 * $1 - name of property. e.g. "params.1.foobar"',
        'templatedata-invalid-value' => 'Error message when a property that 
cannot contain free-form text has an invalid value.
 * $1 - name of property. e.g. "params.1.type"',
+       'templatedata-invalid-length' => 'Error message when generated JSON\'s 
length exceed database limits.
+* $1 - length of generated JSON
+* $2 - maximal allowed length',
 );
 
 /** Asturian (asturianu)
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index 4a4a53e..6f986e4 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -304,6 +304,13 @@
                        }
                }
 
+               $maxlength = 65535; // Size of MySQL 'blob' field
+               $length = strlen( $this->getJSON() );
+
+               if ( $length > $maxlength ) {
+                       return Status::newFatal( 'templatedata-invalid-length', 
$length, $maxlength );
+               }
+
                return Status::newGood();
        }
 
diff --git a/tests/TemplateDataBlobTest.php b/tests/TemplateDataBlobTest.php
index 35a4c85..cea30aa 100644
--- a/tests/TemplateDataBlobTest.php
+++ b/tests/TemplateDataBlobTest.php
@@ -304,6 +304,13 @@
                                }',
                                'status' => true
                        ),
+                       array(
+                               'input' => '{
+                                       "description": "' . str_repeat( 'X', 
65535 ) . '",
+                                       "params": {}
+                               }',
+                               'status' => 'Data too long to save (999 bytes, 
limit is 65535)'
+                       ),
                );
                $calls = array();
                foreach ( $cases as $case ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/75324
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9c7115a951f126844bc70755bff12e8cd5fc2be1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Matmarex <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to