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

Treat strings greater than int max value as non-numeric #17459

Merged
merged 1 commit into from Oct 31, 2014

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Oct 31, 2014

Sufficiently large integers cause find and find_by to raise
StatementInvalid instead of RecordNotFound or just returning nil.
Normally, we cast junk input to nil, but we can't do so here, as it
can cause MySQL to blow up. 0 is what you would get for any other
non-numeric string, so we use the same value here.

Fixes #17380

Sufficiently large integers cause `find` and `find_by` to raise
`StatementInvalid` instead of `RecordNotFound` or just returning `nil`.
Given that we can't cast to `nil` for `Integer` like we would with junk
data for other types, we raise a `RangeError` instead, and rescue in
places where it would be highly unexpected to get an exception from
casting.

Fixes rails#17380
sgrif added a commit that referenced this pull request Oct 31, 2014
Treat strings greater than int max value as out of range
@sgrif sgrif merged commit ecb3113 into rails:master Oct 31, 2014
@sgrif sgrif deleted the sg-find-by-large-numbers branch October 31, 2014 18:16
kamipo added a commit to kamipo/rails that referenced this pull request Sep 6, 2016
Raising `RangeError` was introduced in order to ease to handle out of
range numbers for `find` and `find_by` in postgresql adapter with
prepared statements since rails#17459. At that time, `Type::Integer` assumed
implicit default byte size is 4 bytes due to `extract_limit` in
postgresql adapter did not extract an integer byte size correctly.
That assumption is harmful for other adapters and caused rails#22594.
In rails#26386, it is fixed to register integer types limit correctly.
The handling whether out of range or not is only needed with explicit
`limit`, and `Type::BigInteger` is no longer needed.

Fixes rails#22594.
kamipo added a commit to kamipo/rails that referenced this pull request Aug 20, 2017
Raising `RangeError` was introduced in order to ease to handle out of
range numbers for `find` and `find_by` in postgresql adapter with
prepared statements since rails#17459. At that time, `Type::Integer` assumed
implicit default byte size is 4 bytes due to `extract_limit` in
postgresql adapter did not extract an integer byte size correctly.
That assumption is harmful for other adapters and caused rails#22594.
In rails#26386, it is fixed to register integer types limit correctly.
The handling whether out of range or not is only needed with explicit
`limit`, and `Type::BigInteger` is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In PostgreSQL, find_by('9999999999999999999999999999999') raises an error instead of returning nil
1 participant