I’ve run into a strange bug that I need some help with. I have a model
with a binary column. I’m using Postgres 8.2.4 on the backend. For the
majority of cases, I’m able to store and retrieve binary content using
this setup with no problem. However, I’ve found two test cases that
fail. Consider the following test code, taken from one of my actions:
The test file I write out here contains out the binary data as
expected, so I know that @incoming_blob is correct.
f = File.open(“/tmp/incoming_blob”, “w+”)
f.write @incoming_blob
f.close
Set the value in the AR record, but don’t even save it.
@staged_extension.value = @incoming_blob
Now write out the value from the AR record, and it is truncated to
the first null byte.
f = File.open(“/tmp/from_ar_#{params[:extension_local_ref]}”, “w+”)
f.write @staged_extension.value
f.close
I’ve done the same thing from the console. It seems that the act of
assigning the binary String to the ActiveRecord model truncates it to
the first null byte. The really weird thing is that it works for other
blobs (jpgs and other binary data). At first my code was saving to the
database (of course) and I thought the bug was somewhere in the
postgres driver, but it’s not – as you can see here, there is no
database activity going on at all.
There’s nothing fancy going on with the model – I’ve stripped out all
validations on this field, and I still run into this problem.
The two test cases that fail with the code above can be found here:
http://rubycloud.com/pg/1288.1024.jpg
http://rubycloud.com/pg/base.tsz
I have to think given the simplicity of this code that there is a bug
in the ActiveRecord column assignment methods. I’m looking into it,
but any ideas/insight/help you can give would be greatly appreciated.
Thanks,
Matt