-
Notifications
You must be signed in to change notification settings - Fork 179
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
res.ftype(column_number) returns corrupted answer for data types with high OIDs #187
Comments
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). The actual patch with the fix is at: |
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). I went through the code looking for other obvious places where an Oid is passed to a function expecting a signed int, and fixed a few more spots. Second commit is at: |
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). Cool - let me know if you'd prefer I submit it in any particular format. |
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). Cool. Thanks. Any chance of a release ? The git repo doesn't have a Gemfile, so it's near impossible to use bundler's ":git => url" syntax to depend on the project from source instead of a public release. Also regarding actually replicating the issue, you can create a table in postgres specifying "with oids". Insert 2.2 billion rows (doesn't have to be cumulative - delete/truncate every few), then issue a "create type". |
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). Concretely:
Then
Then
Finally "select f from test2" with ruby-pg and check #ftype(1) |
Original comment by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ). If you'll do the above test, do it on a disposable db (initdb foo; postgres -D foo), since you won't be able to rewind the high Oid. |
Original comment by Michael Granger (Bitbucket: ged, GitHub: ged). Okay. I hesitate to try to do this in the regular unit test suite, but thanks for the example. I've pushed a prerelease up to Rubygems; you should be able to use it either by passing |
Original report by Mina Naguib (Bitbucket: [Mina Naguib](https://bitbucket.org/Mina Naguib), ).
The postgresql documentation states "The oid type is currently implemented as an unsigned four-byte integer". Its C typedef in postgres_ext.h is:
We've hit a case in our DB where a data type (hstore) in pg_type has OID 2163584298, which is below 2^32 but slightly higher than 2^31
When we do a select on a table which returns columns of that type, res.ftype( column_number ) returns a corrupted negative number
I believe the bug is in pg_result.c function pgresult_ftype:
This takes the 32-bit unsigned Oid and passes it to INT2NUM which treats it as a signed int, causing the corruption.
The fix I've applied locally is very simply to call UINT2NUM instead. #ftype then returns the correct positive Oid (which is needed in rails as it joins it on data collected from pg_type)
The text was updated successfully, but these errors were encountered: