Skip to content
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

setenv crashes with UTF-8 string #765

Closed
xRandomGuy opened this issue May 25, 2013 · 4 comments
Closed

setenv crashes with UTF-8 string #765

xRandomGuy opened this issue May 25, 2013 · 4 comments

Comments

@xRandomGuy
Copy link

xRandomGuy commented May 25, 2013

When JRuby is reading all envs, passing UTF-8 string to setenv crashes with IllegalArgumentException.

java.lang.IllegalArgumentException
        at java.nio.Buffer.position(Buffer.java:236)
!       at jnr.ffi.provider.converters.CharSequenceParameterConverter.toNative(CharSequenceParameterConverter.java:125)
        at jnr.posix.LinuxLibC$jnr$ffi$0.setenv(Unknown Source)
        at jnr.posix.BaseNativePOSIX.setenv(BaseNativePOSIX.java:303)
        at jnr.posix.CheckedPOSIX.setenv(CheckedPOSIX.java:301)
        at jnr.posix.LazyPOSIX.setenv(LazyPOSIX.java:303)
!       at org.jruby.RubyGlobal$StringOnlyRubyHash.case_aware_op_aset(RubyGlobal.java:424)
        at org.jruby.RubyGlobal$CaseInsensitiveStringOnlyRubyHash.op_aset(RubyGlobal.java:335)
        at org.jruby.RubyGlobal$StringOnlyRubyHash.op_aset19(RubyGlobal.java:387)
        at org.jruby.RubyHash$28.visit(RubyHash.java:1793)
        at org.jruby.RubyHash.visitAll(RubyHash.java:636)
        at org.jruby.RubyHash.replaceCommon19(RubyHash.java:1837)
        at org.jruby.RubyHash.replace19(RubyHash.java:1791)
        at org.jruby.RubyHash$INVOKER$i$1$0$replace19.call(RubyHash$INVOKER$i$1$0$replace19.gen)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
        at org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
        at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
@enebo
Copy link
Member

enebo commented May 25, 2013

The other detail to this report is that the default Java charset was not UTF-8. So the Converter was trying to set the position too large since the string ended up having more bytes than expected.

@xRandomGuy
Copy link
Author

xRandomGuy commented May 25, 2013

My default java charset IS indeed UTF-8
Setting LANG=C MAKES IT PASS and 'my locale chars' are turning into '?' which is acceptable in this case.

@enebo
Copy link
Member

enebo commented May 25, 2013

yeah I misunderstood our irc conversation. I think perhaps the crash is because the string length is longer than average # of bytes now:

ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[(int) (string.length() * encoder.averageBytesPerChar()) + 4]);

I suspect this error will go away if we use maxBytesPerChar. @wmeissner what do you think?

@headius
Copy link
Member

headius commented Nov 12, 2014

This appears to work fine in 9k.

$ jruby -e "ENV['foo'] = 'føø'; system 'echo \$foo'"
føø

@headius headius closed this as completed Nov 12, 2014
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Nov 12, 2014
@headius headius self-assigned this Nov 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants