Skip to content

Commit 9497d4d

Browse files
committed
1 parent 52298bc commit 9497d4d

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

‎ext/enterprise_script_service/script_data.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,11 @@ mrb_value msgpack_to_ruby(me_mruby_engine &engine, const msgpack::object &msgpac
183183
engine.check_exception();
184184
return ruby_value;
185185
} else if (msgpack_value.type == msgpack::type::STR) {
186-
auto string_value = msgpack_value.as<std::string>();
187-
auto ruby_value = mrb_str_new(engine.state, string_value.data(), string_value.size());
186+
auto ruby_value = mrb_str_new(engine.state, msgpack_value.via.str.ptr, msgpack_value.via.str.size);
188187
engine.check_exception();
189188
return ruby_value;
190189
} else if (msgpack_value.type == msgpack::type::BIN) {
191-
auto string_value = msgpack_value.as<std::vector<char>>();
192-
auto ruby_value = mrb_str_new(engine.state, string_value.data(), string_value.size());
190+
auto ruby_value = mrb_str_new(engine.state, msgpack_value.via.str.ptr, msgpack_value.via.str.size);
193191
engine.check_exception();
194192
return ruby_value;
195193
} else if (msgpack_value.type == msgpack::type::ARRAY) {

‎spec/script_core_spec.rb

+41
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,45 @@ def foo
269269
expect(result.output).to eq(nil)
270270
expect(result.stdout).to eq("hello")
271271
end
272+
273+
it "accepts large inputs" do
274+
result = ScriptCore.run(
275+
input: "a" * 180 * 1024, # 180KiB
276+
sources: [],
277+
timeout: 1000,
278+
)
279+
expect(result.success?).to be(true)
280+
end
281+
282+
it "fails gracefully when input is too large" do
283+
result = ScriptCore.run(
284+
input: "a" * 8 * 1024 * 1024, # 8MiB, total limit
285+
sources: [],
286+
timeout: 1000,
287+
)
288+
expect(result.success?).to be(false)
289+
expect(result.errors).to eq([ScriptCore::EngineMemoryQuotaError.new])
290+
end
291+
292+
it "roundtrips input with null bytes" do
293+
assert_roundtrip_input("foo\0bar")
294+
end
295+
296+
it "roundtrips emojis" do
297+
assert_roundtrip_input("😅")
298+
end
299+
300+
private
301+
302+
def assert_roundtrip_input(input)
303+
result = ScriptCore.run(
304+
input: input,
305+
sources: [
306+
["foo", "@output = @input"],
307+
],
308+
timeout: 1000,
309+
)
310+
expect(result.success?).to be(true)
311+
expect(result.output).to eq(input)
312+
end
272313
end

0 commit comments

Comments
 (0)