Skip to content

Commit

Permalink
Fix #14014: Search number > 2147483647 fails on 64-bit systems
Browse files Browse the repository at this point in the history
When a numeric search term is entered, the Filter API will only check
for matches in the bug and bugnote id fields when the search term is
within a valid range.

This was never an issue on 32-bit systems, but on 64-bit OS, PostgreSQL
throws an "integer out of range" error when executing the query because
the search term is cast to (int) and PHP_INT_MAX is greater than the
largest value allowed for the numeric DB fields (4-byte int, 2^31-1).

This issue does not exist on MySQL as the value is capped to the maximum
allowed; behavior was not tested on Oracle, DB2 or MSSQL.

The fix for PostgreSQL behavior is a hack, but I can't think of any
better solution (ideally, we should be able to query the DB for the
maximum allowed value for a field).
  • Loading branch information
dregad committed Mar 15, 2012
1 parent 6540f01 commit 4618dcd
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions core/filter_api.php
Expand Up @@ -1957,11 +1957,20 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_where_params[] = $c_search;

if( is_numeric( $t_search_term ) ) {
$c_search_int = (int) $t_search_term;
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
$t_where_params[] = $c_search_int;
$t_where_params[] = $c_search_int;
// PostgreSQL on 64-bit OS hack (see #14014)
if( PHP_INT_MAX > 0x7FFFFFFF && db_is_pgsql() ) {
$t_search_max = 0x7FFFFFFF;
} else {
$t_search_max = PHP_INT_MAX;
}
// Note: no need to test negative values, '-' sign has been removed
if( $t_search_term <= $t_search_max ) {
$c_search_int = (int) $t_search_term;
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
$t_where_params[] = $c_search_int;
$t_where_params[] = $c_search_int;
}
}

$t_textsearch_where_clause .= ' )';
Expand Down

0 comments on commit 4618dcd

Please sign in to comment.