https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-01-16T23:27:48ZRuby Issue Tracking SystemRuby master - Bug #15543: rb_str_set_len should clear code rangehttps://redmine.ruby-lang.org/issues/15543?journal_id=763642019-01-16T23:27:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>It isn't an issue of <code>rb_str_set_len</code>.<br>
The string isn't valid encoding by <code>@s.RSTRING_PTR_set(@str, 2, 0x80)</code>.<br>
You should call <code>rb_str_modify</code> before modifying a string object.</p> Ruby master - Bug #15543: rb_str_set_len should clear code rangehttps://redmine.ruby-lang.org/issues/15543?journal_id=763652019-01-17T00:03:03ZEregon (Benoit Daloze)
<ul></ul><p>I think few people know about this, and <code>rb_str_modify</code> isn't documented in doc/extension.rdoc.<br>
I guess some C extensions ignore this requirement and could have bugs because of it.</p>
<p>Isn't it simpler and safer to clear the coderange, as it's done for, e.g., <code>rb_str_resize()</code> ?</p> Ruby master - Bug #15543: rb_str_set_len should clear code rangehttps://redmine.ruby-lang.org/issues/15543?journal_id=763882019-01-18T02:43:45Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><code>rb_str_set_len</code> is not the true problem.<br>
Should <code>RSTRING_PTR</code> make the object unshared and clear the code range?<br>
Or enclose it only for the core and prohibit in extension libraries?</p>
<p>Hmmm, the last choice may be the best, I think.</p> Ruby master - Bug #15543: rb_str_set_len should clear code rangehttps://redmine.ruby-lang.org/issues/15543?journal_id=764252019-01-20T14:44:32ZEregon (Benoit Daloze)
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p><code>rb_str_set_len</code> is not the true problem.<br>
Should <code>RSTRING_PTR</code> make the object unshared and clear the code range?</p>
</blockquote>
<p>That sounds safer, because indeed as soon as the C code can access the <code>char*</code> it can change it.</p>
<blockquote>
<p>Or enclose it only for the core and prohibit in extension libraries?</p>
</blockquote>
<p>I'm not sure what you mean?</p>
<p>Do you mean removing rb_str_set_len() or RSTRING_PTR from the public C-API?<br>
Or do you mean in core, a special version of RSTRING_PTR would be used?<br>
Or something else?</p>