SecurityError: string contains null byte - when POST'ing binary data

81 views
Skip to first unread message

Aditya Rao

unread,
May 6, 2014, 4:55:52 PM5/6/14
to typh...@googlegroups.com
Hi, 

I'm trying to use typhoeus to send thrift object that is serialized using the Thrift Compact Protocol. Now, the compact serialized appends a zero byte marker at the end of the byte array. For example : 

[31] pry(main)> point = Thrift.base_api.Point.new(110.14, 42.5)
[32] pry(main)> point_bytes = Thrift::CompactSerializer.serialize(point)
=> byte[23, 41, 92, -113, -62, -11, -120, 91, 64, 23, 0, 0, 0, 0, 0, 64, 69, 64, 0]@3067b7c8
[34] pry(main)> point_bytes[point_bytes.length - 1]
=> 0
[35] pry(main)> point_bytes.to_s
=> "\x17)\\\x8F\xC2\xF5\x88[@\x17\x00\x00\x00\x00\x00@E@\x00"

Now when I try to POST this data using Tyhpoeus to a server that accepts x-thrift content type, I keep running into the follow error : 

SecurityError: string contains null byte
from /Users/aditya/.rvm/gems/jruby-1.7.8@nitro/gems/ethon-0.7.0/lib/ethon/curls/options.rb:83:in `set_option'

Here are what my request options look like : 

[42] pry(main)> request = Typhoeus::Request.new(url, {
[42] pry(main)*     :method => :post,
[42] pry(main)*     :headers => { 'Content-Type' => 'application/x-thrift',
[42] pry(main)*       'Accept' => 'application/x-thrift',
[42] pry(main)*       'Content-Length' => point_bytes.size},
[42] pry(main)*     :body => point_bytes.to_s
[42] pry(main)* })

Not sure what I'm missing here. I've tried various combinations using :postfields and :postfieldsize but with no luck. Is there anyway to get around this issue (any curl opts I should be using here). When I write this data to a file and POST using the command line curl (--data--binary), it seems to work OK. 

I'm running typhoeus v0.6.8 on jruby-1.7.8.

Thanks,

Aditya

me

unread,
May 16, 2014, 2:42:47 AM5/16/14
to typh...@googlegroups.com
Hello Aditya,

sorry for the late response. This is strange and it should not happen. Could you open a github issue? That would help me a lot. 
Reply all
Reply to author
Forward
0 new messages