mruby/mruby — pull request #1484 by fjmilens3 (2013-08-22 21:54:26+00:00)
Title: Bug in String#start_with? resulting from incorrect length determination

There is a bug in the current implementation of String#start_with? that manifests itself under special conditions. The current logic uses the minimum size of the two strings and performs a memory comparison, which is not valid under certain conditions.

For example, if we have the string "h" and call #start_with?("hello"), we would expect the result to be false since "h" doesn't start with "hello." However, we end up with a value of true in the current mruby because of the above string length issue, where we're only comparing to the minimum string length.

Basically, if the left-hand string is smaller than the right-hand string, there's no way that it could start with the right-hand string, and the result should be false.

I've committed both a test case (which failed before my fix) and a fix for the issue in the corresponding C code (where I'm skipping the comparison on strings that don't meet the length criterion).