Issue #18343 has been updated by xtkoba (Tee KOBAYASHI).


Proposed patch:

```diff
--- ruby-2.6.8/pack.c.orig
+++ ruby-2.6.8/pack.c
@@ -330,7 +330,7 @@ pack_pack(int argc, VALUE *argv, VALUE a
 	if (buffer != Qundef && !RB_TYPE_P(buffer, T_STRING))
 	    rb_raise(rb_eTypeError, "buffer must be String, not %s", rb_obj_classname(buffer));
     }
-    if (buffer)
+    if (buffer && buffer != Qundef)
 	res = buffer;
     else
 	res = rb_str_buf_new(0);
```

----------------------------------------
Bug #18343: empty hash passed to Array#pack causes Segmentation fault (2.6)
https://bugs.ruby-lang.org/issues/18343#change-94687

* Author: Ethan (Ethan -)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.8p205 (2021-07-07 revision 67951) [x86_64-linux]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
passing an empty hash to `Array#pack` segfaults from ruby 2.4 to ruby 2.6 on ubuntu, macos, and windows.

```ruby
[0].pack('c', {})
```

pack takes a keyword argument, and handles unknown keywords, but the empty hash segfaults.

here is the error trace in a github workflow running only the above expression: https://github.com/notEthan/jsi/runs/4226433638 (other ruby versions and OSes are part of the same run)




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>