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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding of string created from literal changes as side effect of ENV mutation #7166

Closed
ivoanjo opened this issue Mar 31, 2022 · 3 comments 路 Fixed by #7167
Closed

Encoding of string created from literal changes as side effect of ENV mutation #7166

ivoanjo opened this issue Mar 31, 2022 · 3 comments 路 Fixed by #7167
Milestone

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented Mar 31, 2022

Hey hey! 馃憢

As always, thanks for making JRuby awesome! I'm working on adding JRuby 9.3 to the ddtrace gem CI and ran into this really weird behavior 馃憖

Environment Information

Provide at least:

  • JRuby version: jruby 9.3.4.0 (2.6.8) 2022-03-23 eff48c1ebf OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
  • Operating system and platform: Linux docker-desktop 5.10.104-linuxkit #1 SMP Wed Mar 9 19:05:23 UTC 2022 x86_64 GNU/Linux

Expected Behavior

Testcase:

puts RUBY_DESCRIPTION

utf8 = ''.encode(::Encoding::UTF_8).freeze
puts utf8.encoding

ENV['FOO'] = ''

puts utf8.encoding

When executed in the jruby:9.3.4.0-jre11 docker image with LANG=en_US.UTF-8, e.g.:

$ docker run -ti -v `pwd`:/working jruby:9.3.4.0-jre11 /bin/bash
root# LANG=en_US.UTF-8 jruby working/encoding_bug.rb
jruby 9.3.4.0 (2.6.8) 2022-03-23 eff48c1ebf OpenJDK 64-Bit Server VM 11.0.14.1+1 on 11.0.14.1+1 +jit [x86_64-linux]
UTF-8
US-ASCII

This doesn't happen if don't change LANG. It also doesn't happen on 9.2, but seems to be there already in 9.3.0.0 so somewhere in the 9.3 work this bug came about.

@headius
Copy link
Member

headius commented Mar 31, 2022

Likely that some shared ByteList instances are getting modified directly by ENV when they should not be.

@headius headius added this to the JRuby 9.3.5.0 milestone Mar 31, 2022
headius added a commit to headius/jruby that referenced this issue Mar 31, 2022
These strings should not reference their old objects, since we
may need to negotiate a new encoding for them to fit the host
system.

Fixes jruby#7166
@headius
Copy link
Member

headius commented Mar 31, 2022

I pushed #7167 which seems to fix this, but we should audit the related code to see where along the way CRuby dups the incoming value string (and avoid doing it too much when we do not need to).

@ivoanjo
Copy link
Contributor Author

ivoanjo commented Apr 1, 2022

Thanks for looking into this! 馃憤馃檱

@headius headius closed this as completed in eed4786 Apr 7, 2022
@headius headius modified the milestones: JRuby 9.3.5.0, JRuby 9.3.6.0 Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants