Skip to content

Commit 04a5fb5

Browse files
committedMar 16, 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 fca6d03 commit 04a5fb5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

Diff for: ‎core/filter_api.php

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

19841984
if( is_numeric( $t_search_term ) ) {
1985-
$c_search_int = (int) $t_search_term;
1986-
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
1987-
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
1988-
$t_where_params[] = $c_search_int;
1989-
$t_where_params[] = $c_search_int;
1985+
// PostgreSQL on 64-bit OS hack (see #14014)
1986+
if( PHP_INT_MAX > 0x7FFFFFFF && db_is_pgsql() ) {
1987+
$t_search_max = 0x7FFFFFFF;
1988+
} else {
1989+
$t_search_max = PHP_INT_MAX;
1990+
}
1991+
// Note: no need to test negative values, '-' sign has been removed
1992+
if( $t_search_term <= $t_search_max ) {
1993+
$c_search_int = (int) $t_search_term;
1994+
$t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
1995+
$t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
1996+
$t_where_params[] = $c_search_int;
1997+
$t_where_params[] = $c_search_int;
1998+
}
19901999
}
19912000

19922001
$t_textsearch_where_clause .= ' )';

0 commit comments

Comments
 (0)
Please sign in to comment.