Skip to content

Commit 31c1ee3

Browse files
committed
Initial move to SnakeYAML Engine
See jruby/jruby#7570 for some of the justification for this move. We only require the parser from SnakeYAML, but in the original form it is encumbered with Java object serialization code that keeps getting flagged as a CVE risk. We disagree with the assessment, at least as it pertains to JRuby (we do not use the code in question) but our inclusion of the library continues to get flagged by auditing tools. This commit starts the process of moving to the successor library, SnakeYAML Engine. The parser API is largely unchanged, except as seen in this commit. No Java exceptions are thrown, but a number of Psych tests fail (possibly due to Engine being YAML 1.2 only).
1 parent 3ade585 commit 31c1ee3

File tree

8 files changed

+233
-220
lines changed

8 files changed

+233
-220
lines changed

Mavenfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#-*- mode: ruby -*-
22

3-
jar 'org.yaml:snakeyaml:${snakeyaml.version}'
3+
jar 'org.snakeyaml:snakeyaml-engine:${snakeyaml.version}'
44

55
plugin :dependency, '2.8', :outputFile => 'pkg/classpath'
66

ext/java/org/jruby/ext/psych/PsychEmitter.java

Lines changed: 109 additions & 96 deletions
Large diffs are not rendered by default.

ext/java/org/jruby/ext/psych/PsychLibrary.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
***** END LICENSE BLOCK *****/
2828
package org.jruby.ext.psych;
2929

30-
import java.io.InputStream;
31-
import java.io.IOException;
32-
import java.util.Properties;
33-
3430
import org.jcodings.Encoding;
3531
import org.jcodings.specific.UTF16BEEncoding;
3632
import org.jcodings.specific.UTF16LEEncoding;
@@ -44,7 +40,10 @@
4440
import org.jruby.runtime.Visibility;
4541
import org.jruby.runtime.builtin.IRubyObject;
4642
import org.jruby.runtime.load.Library;
47-
import org.yaml.snakeyaml.error.Mark;
43+
44+
import java.io.IOException;
45+
import java.io.InputStream;
46+
import java.util.Properties;
4847

4948
public class PsychLibrary implements Library {
5049
private static final String DUMMY_VERSION = "0.0";
@@ -54,7 +53,7 @@ public void load(final Ruby runtime, boolean wrap) {
5453

5554
// load version from properties packed with the jar
5655
Properties props = new Properties();
57-
try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.yaml/snakeyaml/pom.properties") ) {
56+
try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.snakeyaml/snakeyaml-engine/pom.properties") ) {
5857
props.load(is);
5958
}
6059
catch( IOException e ) {
@@ -66,27 +65,6 @@ public void load(final Ruby runtime, boolean wrap) {
6665
snakeyamlVersion = snakeyamlVersion.substring(0, snakeyamlVersion.length() - "-SNAPSHOT".length());
6766
}
6867

69-
// Try to determine if we have a new enough SnakeYAML.
70-
// Versions before 1.21 removed a Mark constructor that JRuby uses.
71-
// See https://github.com/bundler/bundler/issues/6878
72-
if (snakeyamlVersion.equals(DUMMY_VERSION)) {
73-
try {
74-
// Use reflection to try to confirm we have a new enough version
75-
Mark.class.getConstructor(String.class, int.class, int.class, int.class, int[].class, int.class);
76-
} catch (NoSuchMethodException nsme) {
77-
throw runtime.newLoadError("bad SnakeYAML version, required 1.21 or higher; check your CLASSPATH for a conflicting jar");
78-
}
79-
} else {
80-
// Parse version string to check for 1.21+
81-
String[] majorMinor = snakeyamlVersion.split("\\.");
82-
83-
if (majorMinor.length < 2 || Integer.parseInt(majorMinor[0]) < 1 || Integer.parseInt(majorMinor[1]) < 21) {
84-
throw runtime.newLoadError(
85-
"bad SnakeYAML version " + snakeyamlVersion +
86-
", required 1.21 or higher; check your CLASSPATH for a conflicting jar");
87-
}
88-
}
89-
9068
RubyString version = runtime.newString(snakeyamlVersion + ".0");
9169
version.setFrozen(true);
9270
psych.setConstant("SNAKEYAML_VERSION", version);

ext/java/org/jruby/ext/psych/PsychParser.java

Lines changed: 112 additions & 90 deletions
Large diffs are not rendered by default.

ext/java/org/jruby/ext/psych/PsychToRuby.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929

3030
import org.jruby.Ruby;
3131
import org.jruby.RubyClass;
32+
import org.jruby.RubyException;
3233
import org.jruby.RubyModule;
3334
import org.jruby.RubyObject;
34-
import org.jruby.RubyException;
3535
import org.jruby.anno.JRubyMethod;
3636
import org.jruby.exceptions.RaiseException;
3737
import org.jruby.runtime.ThreadContext;
3838
import org.jruby.runtime.builtin.IRubyObject;
39-
import static org.jruby.runtime.Visibility.*;
39+
40+
import static org.jruby.runtime.Visibility.PRIVATE;
4041

4142
public class PsychToRuby {
4243
public static void initPsychToRuby(Ruby runtime, RubyModule psych) {

lib/psych/versions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ module Psych
55
VERSION = '5.0.1'
66

77
if RUBY_ENGINE == 'jruby'
8-
DEFAULT_SNAKEYAML_VERSION = '1.33'.freeze
8+
DEFAULT_SNAKEYAML_VERSION = '2.5'.freeze
99
end
1010
end

lib/psych_jars.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
require 'psych.jar'
33

44
require 'jar-dependencies'
5-
require_jar('org.yaml', 'snakeyaml', Psych::DEFAULT_SNAKEYAML_VERSION)
5+
require_jar('org.snakeyaml', 'snakeyaml-engine', Psych::DEFAULT_SNAKEYAML_VERSION)

psych.gemspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ DESCRIPTION
5252
"ext/java/org/jruby/ext/psych/PsychLibrary.java",
5353
"ext/java/org/jruby/ext/psych/PsychParser.java",
5454
"ext/java/org/jruby/ext/psych/PsychToRuby.java",
55-
"ext/java/org/jruby/ext/psych/PsychYamlTree.java",
5655
"lib/psych_jars.rb",
5756
"lib/psych.jar"
5857
]
59-
s.requirements = "jar org.yaml:snakeyaml, #{version_module::Psych::DEFAULT_SNAKEYAML_VERSION}"
58+
s.requirements = "jar org.snakeyaml:snakeyaml-engine, #{version_module::Psych::DEFAULT_SNAKEYAML_VERSION}"
6059
s.add_dependency 'jar-dependencies', '>= 0.1.7'
6160
else
6261
s.extensions = ["ext/psych/extconf.rb"]

0 commit comments

Comments
 (0)