Skip to content

Commit 3f19d1e

Browse files
committed
fix: Don't call #size on complex objects
Limit invocation of #size to known-safe objects - initially, Array and Hash.
1 parent c083588 commit 3f19d1e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/appmap/event.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def display_string(value)
6060
final ? value_string : encode_display_string(value_string)
6161
end
6262

63+
def add_size(param, value)
64+
# Don't risk calling #size on things like data-access objects, which can and will issue queries for this information.
65+
if value.is_a?(Array) || value.is_a?(Hash)
66+
param[:size] = value.size
67+
end
68+
end
69+
6370
def add_schema(param, value)
6471
begin
6572
if value.respond_to?(:keys)
@@ -224,7 +231,7 @@ def build_from_invocation(defined_class, method, receiver, arguments, event: Met
224231
value: display_string(value),
225232
kind: param_type
226233
}.tap do |param|
227-
param[:size] = value.size if value.respond_to?(:size) && value.is_a?(Enumerable)
234+
add_size param, value
228235
end
229236
end
230237
event.receiver = {
@@ -289,7 +296,7 @@ def build_from_invocation(parent_id, return_value, exception, elapsed: nil, even
289296
value: display_string(return_value),
290297
object_id: return_value.__id__
291298
}.tap do |param|
292-
param[:size] = return_value.size if return_value.respond_to?(:size) && return_value.is_a?(Enumerable)
299+
add_size param, return_value
293300
add_schema param, return_value if parameter_schema && !exception
294301
end
295302
end

0 commit comments

Comments
 (0)