Hash with key containing \0 causes a SIGBUS
Reported by Michael Klishin | February 18th, 2008 @ 10:11 AM | in 1.0 preview
Here's what I have on Intel Mac running OS X Leopard:
stormblast:rubinius antares$ shotgun/rubinius -e 'print ({:"\0test\0" =>1}).inspect'
An error has occured: Bus violation (SIGBUS) (10)
Ruby backtrace:
0x1402240 String#to_sexp+56 in kernel/core/string.rb:2174
0x14021b8 Class#compile_string+57 in lib/compiler/compiler.rb:38
0x2565078 Class#compile_string+63 in kernel/core/compile.rb:69
0x25650e4 Kernel#eval+146 in kernel/core/eval.rb:88
0x2565154 Class#execute+16 in kernel/core/compile.rb:73
0x23af180 #__script__+871 in kernel/loader.rb:158
VM Registers:
IP: 0056
SP: 0221
Exception: none
Comments and changes to this ticket
-
Matthijs Langenberg February 18th, 2008 @ 11:55 AM
Just noticed that this only happens when the value is a number.
irb(main):006:0> print ({:"\0test\0" => 'bar' }).inspect
{:bar=>""}=> nil
Is still odd though
-
Matthijs Langenberg February 29th, 2008 @ 04:16 PM
Just ran it on MRI:
print ({:"\0test\0" => 1 }).inspect
SyntaxError: compile error
(irb):2: symbol cannot contain '\0'
from (irb):2
from :0
So
:"\0"should have raised a SyntaxError. I will write a spec for that, and maybe even an implementation if I feel lucky. -
Matthijs Langenberg February 19th, 2008 @ 01:33 AM
On Rubinius:
irb(main):010:0> "\0".to_sym
ArgumentError: symbol string may not contain `\0'
from String#to_sym at kernel/core/string.rb:1674
from Object#irb_binding {} at (irb):10
irb(main):011:0> :"\0"
=> :
-

Michael Klishin February 20th, 2008 @ 04:30 AM
Yeah, \0 is prohibited in symbol name on MRI. Have you had a chance to spec this out?
-
Matthijs Langenberg February 20th, 2008 @ 01:34 PM
No, I tried but I found it pretty hard to grasp. This bug doesn't occur in an eval, so:
it 'The string may not contain \0' do
lambda { eval %{:"\0"} }.should raise_error(SyntaxError)
end
Does raise an error like it should.
En we can't rescue this exception at this level.
Any ideas?
-
Dirkjan Bussink February 21st, 2008 @ 01:39 PM
- → State changed from new to open
Well, if we want to match mri, just :"\0" should give a parse error. Looks like a perfect candidate for a spec then :).
-
Ryan Davis February 29th, 2008 @ 04:16 PM
- → Assigned user changed from to Evan Phoenix
-
Charles Comstock November 25th, 2008 @ 09:00 AM
- → Tag changed from to osx segfault sigbus string
This no longer causes a SIGBUS, but it throws an Argument Error instead of a Syntax Error. Is that acceptable, can we close this?
-
Brian Ford November 25th, 2008 @ 02:26 PM
- → State changed from open to resolved
Fixed in 789f7825e.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
