Data corruption: hexadecimal data interpreted as binary data #7619

Closed
xb opened this Issue Sep 12, 2012 · 10 comments

5 participants

@xb
xb commented Sep 12, 2012

https://github.com/rails/rails/blob/232d2223ebcfe5c9e0425c821f5d30a7d5968512/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb#L49

sometimes generates a binary string and sometimes generates a hexadecimal string:

"010F" will be treated as hexadecimal string
"010E" will be treated as hexadecimal string
"010D" will be treated as hexadecimal string
"010C" will be treated as hexadecimal string
"010B" will be treated as hexadecimal string
"010A" will be treated as hexadecimal string
"0109" will be treated as hexadecimal string
"0108" will be treated as hexadecimal string
"0107" will be treated as hexadecimal string
"0106" will be treated as hexadecimal string
"0105" will be treated as hexadecimal string
"0104" will be treated as hexadecimal string
"0103" will be treated as hexadecimal string
"0102" will be treated as hexadecimal string
"0101" will be treated as binary string
"0100" will be treated as binary string

This ambiguity is highly questionable and should be resolved somehow (maybe hexadecimal strings should be discouraged at all).

@kennyj

This is difficult problem.
I guess AR's behavior should be changed.
How about the above commit ?

@steveklabnik
Ruby on Rails member

@kennyj you should submit it as a pull request rather than just attaching a commit to a random issue.

@thiagofm

Any updates when this will be on master? @steveklabnik @kennyj

@kennyj

@thiagofm
I didn't know whether my changing was good. But I don't have new idea.
Anyway I'll try to send PR :-)

@kennyj kennyj added a commit to kennyj/rails that referenced this issue Nov 13, 2012
@kennyj kennyj Fix #7619. 0x prefix must be added when assigning hexadecimal string …
…into bit column in Postgresql, because solving ambiguity.
7d244df
@stouset

@steveklabnik Mind taking another look at this? There's code ready to go. This could (possibly) break backwards compatibility, so should probably make it out the door before Rails 4 ships.

Leaving it as-is is probably more problematic than just fixing the bug.

@steveklabnik
Ruby on Rails member

I am really bad at ActiveRecord, so I don't know. it looks okay, but I'd prefer @tenderlove or @jonleighton or @carlosantoniodasilva merge.

@thiagofm

I hope this ends up in Rails 4 🙏

@kennyj kennyj added a commit that closed this issue Apr 16, 2013
@kennyj kennyj Fix #7619. 0x prefix must be added when assigning hexadecimal string …
…into bit column in Postgresql, because solving ambiguity.
01a2ac1
@kennyj kennyj closed this in 01a2ac1 Apr 16, 2013
@stouset

Woohoo!

@thiagofm

👍 finally

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