Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4618dcd

Browse files
committedMar 15, 2012
Fix #14014: Search number > 2147483647 fails on 64-bit systems
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).
1 parent 6540f01 commit 4618dcd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎core/filter_api.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -1957,11 +1957,20 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
19571957
$t_where_params[] = $c_search;
19581958

19591959
if( is_numeric( $t_search_term ) ) {
1960-
$c_search_int = (int) $t_search_term;
1961-
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
1962-
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
1963-
$t_where_params[] = $c_search_int;
1964-
$t_where_params[] = $c_search_int;
1960+
// PostgreSQL on 64-bit OS hack (see #14014)
1961+
if( PHP_INT_MAX > 0x7FFFFFFF && db_is_pgsql() ) {
1962+
$t_search_max = 0x7FFFFFFF;
1963+
} else {
1964+
$t_search_max = PHP_INT_MAX;
1965+
}
1966+
// Note: no need to test negative values, '-' sign has been removed
1967+
if( $t_search_term <= $t_search_max ) {
1968+
$c_search_int = (int) $t_search_term;
1969+
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
1970+
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
1971+
$t_where_params[] = $c_search_int;
1972+
$t_where_params[] = $c_search_int;
1973+
}
19651974
}
19661975

19671976
$t_textsearch_where_clause .= ' )';

0 commit comments

Comments
 (0)
Please sign in to comment.