Skip to content

Commit 78b7842

Browse files
committed
Fix database overflow issue when trying to insert content words
1 parent 7ed3f6a commit 78b7842

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

qa-include/db/maxima.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'QA_DB_MAX_BLOB_FILE_NAME_LENGTH' => 255,
4949
'QA_DB_MAX_META_TITLE_LENGTH' => 40,
5050
'QA_DB_MAX_META_CONTENT_LENGTH' => 8000,
51+
'QA_DB_MAX_WORD_COUNT' => 255, // The field is currently a TINYINT so it shouldn't exceed this value
5152

5253
// How many records to retrieve for different circumstances. In many cases we retrieve more records than we
5354
// end up needing to display once we know the value of an option. Wasteful, but allows one query per page.

qa-include/db/post-create.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ function qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $
166166
{
167167
if (count($wordidcounts)) {
168168
$rowstoadd = array();
169-
foreach ($wordidcounts as $wordid => $count)
169+
foreach ($wordidcounts as $wordid => $count) {
170+
if ($count > QA_DB_MAX_WORD_COUNT) {
171+
$count = QA_DB_MAX_WORD_COUNT;
172+
}
170173
$rowstoadd[] = array($postid, $wordid, $count, $type, $questionid);
174+
}
171175

172176
qa_db_query_sub(
173177
'INSERT INTO ^contentwords (postid, wordid, count, type, questionid) VALUES #',

0 commit comments

Comments
 (0)