From b3671ca9c28695dd566e0438b2a0273e6656e0ea Mon Sep 17 00:00:00 2001 From: Ted Themistokleous <107195283+TedThemistokleous@users.noreply.github.com> Date: Wed, 10 Dec 2025 08:58:21 -0500 Subject: [PATCH] Fix mxr writes and increase read limits (#4480) Fix underflow bug with msgpack_size_limit chunking logic. The underflow makes it appear we had more data than necessary to pack causing EOF and other sorts of packing issues --- src/msgpack.cpp | 3 ++- test/msgpack.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/msgpack.cpp b/src/msgpack.cpp index 2ee49071a71..36819587fa5 100644 --- a/src/msgpack.cpp +++ b/src/msgpack.cpp @@ -34,7 +34,7 @@ constexpr std::size_t msgpack_size_limit = std::numeric_limits::max() template static std::size_t msgpack_chunk_size(const Range& r) { - return 1 + (r.size() - 1) / msgpack_size_limit; + return 1 + (std::max(1, r.size()) - 1) / msgpack_size_limit; } template @@ -81,6 +81,7 @@ MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) break; } case msgpack::type::FLOAT32: + /* Intentional Fall Through This is due to value encoding floats as double. */ case msgpack::type::FLOAT64: { v = o.as(); break; diff --git a/test/msgpack.cpp b/test/msgpack.cpp index e6790510285..df2c927df66 100644 --- a/test/msgpack.cpp +++ b/test/msgpack.cpp @@ -220,5 +220,20 @@ TEST_CASE(test_msgpack_binary2) }); EXPECT(migraphx::to_msgpack(bin) == msgpack_buffer(bin)); } + +TEST_CASE(test_msgpack_binary_empty) +{ + migraphx::value::binary bin{}; + EXPECT(migraphx::to_msgpack(bin) == msgpack_buffer(bin)); +} + +TEST_CASE(test_msgpack_binary_roundtrip_empty) +{ + migraphx::value bin = migraphx::value::binary{}; + auto buffer = migraphx::to_msgpack(bin); + auto mp = migraphx::from_msgpack(buffer); + EXPECT(mp == bin); +} + #endif int main(int argc, const char* argv[]) { test::run(argc, argv); }