Skip to content

Simple search crashes if results parameter set to more than 255 #4725

@nep

Description

@nep

Description of the problem
If you set the simple search result parameter to more than 255, you get a PHP exception due to a database INSERT error.

How To Reproduce

  1. Create template with
{exp:search:simple_form search_in="entries" results="256" result_page="search/index" no_result_page="search/fail"}
<input type="text" name="keywords" id="keywords" />
<input type="submit" />
{/exp:search:simple_form}
  1. Submit the form

Error Messages


Exception Caught
SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'per_page' at row 1:
INSERT INTO `exp_search` (`search_id`, `search_date`, `member_id`, `keywords`, `ip_address`, `total_results`, `per_page`, `query`, `custom_fields`, `result_page`, `no_result_page`, `site_id`) VALUES ('dcb8b1efab31bc05aa5d818ad21733f5', 1740705568, 143, 'therapy', '1.1.1.1', 1833, '256', '[large string omitted]', 'search/index', 'search/fail', 1)
ee/legacy/database/drivers/mysqli/mysqli_connection.php:146

Stack Trace: Please include when reporting this error
#0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(112): CI_DB_mysqli_connection->query()
#1 ee/legacy/database/DB_driver.php(262): CI_DB_mysqli_driver->_execute()
#2 ee/legacy/database/DB_driver.php(177): CI_DB_driver->simple_query()
#3 ee/ExpressionEngine/Addons/search/mod.search.php(265): CI_DB_driver->query()
#4 ee/legacy/libraries/Actions.php(185): Search->do_search()
#5 ee/legacy/libraries/Core.php(682): EE_Actions->__construct()
#6 ee/legacy/controllers/ee.php(51): EE_Core->generate_action()
#7 [internal function]: EE->index()
#8 ee/ExpressionEngine/Core/Core.php(269): call_user_func_array()
#9 ee/ExpressionEngine/Core/Core.php(125): ExpressionEngine\Core\Core->runController()
#10 ee/ExpressionEngine/Boot/boot.php(184): ExpressionEngine\Core\Core->run()
#11 public/index.php(173): require_once('...')
#11 public/index.php(173): require_once('...')

Environment Details:

  • Version: 7.5.7
  • PHP Version 8.2
  • MySQL Version ?
  • OS: doesn't matter
  • Web Server: Apache

Possible Solution

The per_page column is TINYINT, so can only be a max of 255.
But the per_page value is set by the results attribute (RES post variable) and is only limited to max 998:
'per_page' => (isset($_POST['RES']) and is_numeric($_POST['RES']) and $_POST['RES'] < 999) ? $_POST['RES'] : 50,
Solution options:

  • In system/ee/ExpressionEngine/Addons/search/mod.search.php, on line 257 change 999 to 256
  • Change the exp_search column 'per_page' to be SMALLINT (65000ish) or larger instead of TINYINT

The documentation should describe the built-in limit if it is left at 255.
https://docs.expressionengine.com/latest/add-ons/search/simple.html#results

Additional context
Did this bug exist in EE 1.0? Why yes, Rick, yes it did:
/system/modules/search/mod.search.php line 174

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions