Skip to content

Commit dc3ba09

Browse files
committed
add limits to lazy unpacking too
1 parent bab7153 commit dc3ba09

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/mrb_msgpack.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,13 @@ mrb_unpack_msgpack_obj(mrb_state* mrb, const msgpack::object& obj)
918918

919919
case msgpack::type::EXT: {
920920
auto ext_type = obj.via.ext.type();
921-
mrb_msgpack_ctx* ctx = MRB_MSGPACK_CONTEXT(mrb);
922-
if (ext_type == ctx->ext_type && ctx->sym_unpacker != nullptr) {
923-
return ctx->sym_unpacker(mrb, obj);
924-
}
925921
if (ext_type == -1) {
926922
return mrb_msgpack_unpack_timestamp(mrb, obj);
927923
}
924+
mrb_msgpack_ctx* ctx = MRB_MSGPACK_CONTEXT(mrb);
925+
if (ctx->sym_unpacker != nullptr && ext_type == ctx->ext_type) {
926+
return ctx->sym_unpacker(mrb, obj);
927+
}
928928
mrb_value unpacker = mrb_hash_get(
929929
mrb,
930930
ext_unpackers_hash(mrb),
@@ -1108,11 +1108,18 @@ mrb_msgpack_unpack_lazy_m(mrb_state *mrb, mrb_value self)
11081108
mrb_raise(mrb, E_MSGPACK_ERROR, "ObjectHandle is not initialized");
11091109
return mrb_undef_value();
11101110
}
1111-
1111+
msgpack::unpack_limit limit(
1112+
MSGPACK_ARY_LIMIT, // array
1113+
MSGPACK_MAP_LIMIT, // map
1114+
MSGPACK_STR_LIMIT, // str
1115+
MSGPACK_BIN_LIMIT, // bin
1116+
MSGPACK_EXT_LIMIT, // ext
1117+
MSGPACK_DEPTH_LIMIT // depth
1118+
);
11121119
msgpack::unpack(handle->oh,
11131120
RSTRING_PTR(data),
11141121
RSTRING_LEN(data),
1115-
handle->off);
1122+
handle->off, nullptr, nullptr, limit);
11161123

11171124
return object_handle;
11181125
}

test/fuzz.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ def random_pointer(chars)
5757

5858
# 5) Ext‑Type‑Fuzzing
5959
begin
60-
MessagePack.register_ext_type(42, String,
61-
pack: ->(s) { s },
62-
unpack: ->(d) { d }
63-
)
6460
MessagePack.unpack(random_bytes(rand(20), chars))
6561
rescue MessagePack::Error
6662
end

0 commit comments

Comments
 (0)