@@ -1166,20 +1166,24 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option
11661166
11671167 /* Handle maxStalenessSeconds, and make sure it is not combined with primary
11681168 * readPreference */
1169- if (bson_iter_init_find_case (& iter , options , MONGOC_URI_MAXSTALENESSSECONDS ) && BSON_ITER_HOLDS_INT32 (& iter )) {
1170- int32_t max_staleness_seconds = bson_iter_int32 (& iter );
1169+ if (bson_iter_init_find_case (& iter , options , MONGOC_URI_MAXSTALENESSSECONDS ) && BSON_ITER_HOLDS_INT (& iter )) {
1170+ int64_t max_staleness_seconds = bson_iter_as_int64 (& iter );
11711171
11721172 if (max_staleness_seconds != MONGOC_NO_MAX_STALENESS ) {
11731173
11741174 if (max_staleness_seconds < MONGOC_SMALLEST_MAX_STALENESS_SECONDS ) {
1175- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessSeconds to be >= %d, %" PRId32 " given" , MONGOC_SMALLEST_MAX_STALENESS_SECONDS , max_staleness_seconds );
1175+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessSeconds to be >= %d, %" PRId64 " given" , MONGOC_SMALLEST_MAX_STALENESS_SECONDS , max_staleness_seconds );
11761176 mongoc_read_prefs_destroy (new_rp );
11771177
11781178 return false;
11791179 }
11801180
1181- /* max_staleness_seconds is fetched as an INT32, so there is no need to check
1182- * if it exists INT32_MAX as we do in the ReadPreference constructor. */
1181+ if (max_staleness_seconds > INT32_MAX ) {
1182+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected maxStalenessSeconds to be <= %d, %" PRId64 " given" , INT32_MAX , max_staleness_seconds );
1183+ mongoc_read_prefs_destroy (new_rp );
1184+
1185+ return false;
1186+ }
11831187
11841188 if (mongoc_read_prefs_get_mode (new_rp ) == MONGOC_READ_PRIMARY ) {
11851189 phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Primary read preference mode conflicts with maxStalenessSeconds" );
0 commit comments