Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-17746: Signed integer overflow when setting ATTR_TIMEOUT #17854

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Feb 18, 2025

::setAttribute(PDO::ATTR_TIMEOUT, …) accepts a timeout in seconds, but sqlite3_busy_timeout()[1] expects the timeout in milliseconds, which is an int. To avoid signed overflow, we reject values larger than the allowed range.

We also cater to negative values by simply clamping those to zero, since sqlite3_busy_timeout() handles negative values the same as zero.

[1] https://www.sqlite.org/c3ref/busy_timeout.html


@nielsdos said:

I wonder if we should warn in that case to notify the user that no timeout actually was applied.

I'm not sure about this, since that may raise an exception with ERRMODE_EXCEPTION (and possibly even with ERRMODE_WARNING due to a global error handler), and might break working code (not working as intended, but somehow working). Perhaps it's better to postpone that to the master branch.

`::setAttribute(PDO::ATTR_TIMEOUT, …)` accepts a timeout in seconds,
but `sqlite3_busy_timeout()`[1] expects the timeout in milliseconds,
which is an `int`.  To avoid signed overflow, we reject values larger
than the allowed range.

We also cater to negative values by simply clamping those to zero,
since `sqlite3_busy_timeout()` handles negative values the same as
zero.

[1] <https://www.sqlite.org/c3ref/busy_timeout.html>
@cmb69 cmb69 linked an issue Feb 18, 2025 that may be closed by this pull request
@cmb69 cmb69 marked this pull request as ready for review February 18, 2025 17:35
@cmb69 cmb69 requested a review from SakiTakamachi as a code owner February 18, 2025 17:35
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, and point taken about the warning. Thx for the patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signed integer overflow when setting ATTR_TIMEOUT
2 participants