https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-03-04T22:51:08ZRuby Issue Tracking SystemRuby master - Bug #16784: Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or size too big) (ArgumentError)" https://bugs.ruby-lang.org/issues/16784?journal_id=907412021-03-04T22:51:08Zxtkoba (Tee KOBAYASHI)
<ul></ul><p>I have confirmed this issue with a recent 3.1.0dev version (33dc0a070a):</p>
<pre><code>$ ./miniruby -e ""
./miniruby: negative string size (or size too big) (ArgumentError)
</code></pre>
<p>An observation using GDB:</p>
<pre><code>Breakpoint 1, ruby_init_loadpath () at ../ruby.c:614
614 VALUE load_path, archlibdir = 0;
(gdb) next
616 const char *paths = ruby_initial_load_paths;
(gdb)
630 sopath = runtime_libruby_path();
(gdb)
631 libpath = RSTRING_PTR(sopath);
(gdb)
633 p = strrchr(libpath, '/');
(gdb)
634 if (p) {
(gdb)
675 baselen = p - libpath;
(gdb)
676 rb_str_resize(sopath, baselen);
(gdb) p baselen
$1 = 18446743798821772880
(gdb) p p
$2 = 0x0
(gdb) p libpath
$3 = 0x400096a1b0 ""
</code></pre>
<p>It seems that in line 675 <code>baselen</code> is set to a wrong value when <code>p</code> is equal to <code>NULL</code>.</p>
<p>A proposed workaround:</p>
<pre><code>--- a/ruby.c
+++ b/ruby.c
@@ -671,8 +671,11 @@
p = p2;
}
#endif
+ baselen = p - libpath;
+ }
+ else {
+ baselen = 0;
}
- baselen = p - libpath;
rb_str_resize(sopath, baselen);
libpath = RSTRING_PTR(sopath);
#define PREFIX_PATH() sopath
</code></pre> Ruby master - Bug #16784: Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or size too big) (ArgumentError)" https://bugs.ruby-lang.org/issues/16784?journal_id=907512021-03-05T15:01:44Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>I don't know powerpc64le-linux-musl at all, but the patch looks reasonable to me. At least, it should be benign on other environments that now ruby works on. I will merge it.</p> Ruby master - Bug #16784: Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or size too big) (ArgumentError)" https://bugs.ruby-lang.org/issues/16784?journal_id=907552021-03-05T15:50:38Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Keep libpath length non-negative [Bug #16784] When runtime_libruby_path does not include '/', it..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/8ccc12118ea5257f846476088eb9c64944560892">git|8ccc12118ea5257f846476088eb9c64944560892</a>.</p>
<hr>
<p>Keep libpath length non-negative [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Compiling with --enable-load-relative and "musl-gcc -static" yields "negative string size (or siz... (Closed)" href="https://bugs.ruby-lang.org/issues/16784">#16784</a>]</p>
<p>When runtime_libruby_path does not include '/', it attempts to call<br>
rb_str_resize with negative length. This change makes sure that the<br>
length non-negative.</p>
<p>Co-Authored-By: xtkoba (Tee KOBAYASHI) <a href="mailto:xtkoba+ruby@gmail.com" class="email">xtkoba+ruby@gmail.com</a></p>