Skip to content

Commit

Permalink
[Truffle] Fixed an infinite loop in String due to not checking invali…
Browse files Browse the repository at this point in the history
…d input.
  • Loading branch information
nirvdrum committed Mar 30, 2015
1 parent 0c6fedc commit 7ca2f63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/split_tags.txt
@@ -1,4 +1,3 @@
fails:String#split with String splits on multibyte characters
fails:String#split with String taints the resulting strings if self is tainted
fails:String#split with Regexp taints the resulting strings if self is tainted
fails:String#split with Regexp returns an ArgumentError if an invalid UTF-8 string is supplied
Expand Up @@ -9,12 +9,15 @@
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import org.joni.Matcher;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.util.StringSupport;

/**
* Rubinius primitives associated with the Ruby {@code Regexp} class.
Expand Down Expand Up @@ -59,6 +62,17 @@ public RegexpSearchRegionPrimitiveNode(RegexpSearchRegionPrimitiveNode prev) {
public Object searchRegion(RubyRegexp regexp, RubyString string, int start, int end, boolean forward) {
notDesignedForCompilation();

if (regexp.getRegex() == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this));
}

if (string.scanForCodeRange() == StringSupport.CR_BROKEN) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("invalid byte sequence in %s", string.getByteList().getEncoding()), this));
}

final Matcher matcher = regexp.getRegex().matcher(string.getBytes().bytes());

return regexp.matchCommon(string, false, false, matcher, start, end);
Expand Down

0 comments on commit 7ca2f63

Please sign in to comment.