Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix a possible GC crash when GC trigger inside `MessagePack::Buffer.new` (#314).

2022-09-30 1.6.0:

* Fix a potential use-after-free bug in Buffer_free when accessing a packer or unpacker buffer.
Expand Down
2 changes: 1 addition & 1 deletion ext/msgpack/buffer_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static VALUE Buffer_alloc(VALUE klass)
{
msgpack_buffer_t* b;
VALUE buffer = TypedData_Make_Struct(klass, msgpack_buffer_t, &buffer_data_type, b);
rb_ivar_set(buffer, s_at_owner, Qnil);
msgpack_buffer_init(b);
rb_ivar_set(buffer, s_at_owner, Qnil);
return buffer;
}

Expand Down
11 changes: 11 additions & 0 deletions spec/cruby/buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,15 @@
buffer.read_all
expect(ObjectSpace.memsize_of(buffer)).to be == empty_size
end

it "doesn't crash when marking an uninitialized buffer" do
stress = GC.stress
begin
GC.stress = true

MessagePack::Buffer.new
ensure
GC.stress = stress
end
end
end
12 changes: 12 additions & 0 deletions spec/packer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,16 @@ def to_msgpack_ext
[0xc9, 65538, -1].pack('CNC') + "a"*65538
end
end

it "doesn't crash when marking an uninitialized buffer" do
stress = GC.stress
begin
GC.stress = true

MessagePack::Packer.new.buffer
Object.new
ensure
GC.stress = stress
end
end
end
16 changes: 16 additions & 0 deletions spec/unpacker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -866,4 +866,20 @@ def flatten(struct, results = [])
end
end
end

it "doesn't crash when marking an uninitialized buffer" do
if RUBY_PLATFORM == "java"
pending("THe java extension is missing Unpacker#buffer https://github.com/msgpack/msgpack-ruby/issues/315")
end

stress = GC.stress
begin
GC.stress = true

MessagePack::Unpacker.new.buffer
Object.new
ensure
GC.stress = stress
end
end
end