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

xRandomGuy opened this issue May 25, 2013 · 4 comments

setenv crashes with UTF-8 string #765

xRandomGuy opened this issue May 25, 2013 · 4 comments


Copy link

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

        at java.nio.Buffer.position(
!       at jnr.ffi.provider.converters.CharSequenceParameterConverter.toNative(
        at jnr.posix.LinuxLibC$jnr$ffi$0.setenv(Unknown Source)
        at jnr.posix.BaseNativePOSIX.setenv(
        at jnr.posix.CheckedPOSIX.setenv(
        at jnr.posix.LazyPOSIX.setenv(
!       at org.jruby.RubyGlobal$StringOnlyRubyHash.case_aware_op_aset(
        at org.jruby.RubyGlobal$CaseInsensitiveStringOnlyRubyHash.op_aset(
        at org.jruby.RubyGlobal$StringOnlyRubyHash.op_aset19(
        at org.jruby.RubyHash$28.visit(
        at org.jruby.RubyHash.visitAll(
        at org.jruby.RubyHash.replaceCommon19(
        at org.jruby.RubyHash.replace19(
        at org.jruby.RubyHash$INVOKER$i$1$0$$INVOKER$i$1$0$replace19.gen)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(
        at org.jruby.ast.CallOneArgNode.interpret(
        at org.jruby.ast.NewlineNode.interpret(
Copy link

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.

Copy link

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.

Copy link

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?

Copy link

headius commented Nov 12, 2014

This appears to work fine in 9k.

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

@headius headius closed this as completed Nov 12, 2014
@headius headius added this to the JRuby 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
None yet

No branches or pull requests

3 participants