Skip to content

fix(engine): bound the depth of the expanded object display - #5665

Open
adisingh396 wants to merge 1 commit into
boa-dev:mainfrom
adisingh396:fix/display-depth-limit
Open

adisingh396 wants to merge 1 commit into
boa-dev:mainfrom
adisingh396:fix/display-depth-limit

Conversation

@adisingh396

Copy link
Copy Markdown

Summary

console.dir (and %o) reaches log_object_to_internal, which carried only a cycle-detection set and no depth argument. An acyclic chain of plain objects recursed without bound:

  • the indent grows by 4 per level and every line re-emits it, so output is O(depth²); 1200 levels asked for over 12 GB and was OOM-killed, and
  • past depth 16383 the indent exceeds the u16 width accepted by core::fmt and to_string() panics.

This threads a depth counter through log_object_to_internal and its two recursion edges, and collapses at EXPANDED_DEPTH_LIMIT (32) the same way the compact printer already collapses at COMPACT_DEPTH_LIMIT.

Closes #5654

Tests

New unit test display_obj_bounds_nesting_depth builds a 1000-deep object chain and asserts display_obj(true) renders [Object] at the cut instead of exhausting memory/stack or panicking.

  • cargo fmt --all -- --check → clean
  • cargo clippy -p boa_engine --all-targets -- -D warnings → clean
  • cargo test -p boa_engine --lib → test result: ok. 1125 passed; 0 failed (1124 before, +1 new)

Not run here: cargo test --workspace (Windows host, this change is engine-local) and the Test262 suite.

console.dir (and %o) reached log_object_to_internal, which carried only
a cycle-detection set and no depth argument. An acyclic chain of plain
objects therefore recursed without bound: the indent grows 4 per level
and every line re-emits it, so output is O(depth^2) (1200 levels asked
for over 12 GB and was OOM-killed), and past depth 16383 the indent
overflows the u16 width accepted by core::fmt and to_string panics.

Thread a depth counter through log_object_to_internal and both of its
recursion edges, and collapse at EXPANDED_DEPTH_LIMIT (32), the same way
the compact printer already collapses at COMPACT_DEPTH_LIMIT.

Test: a 1000-deep object chain through display_obj(true) renders
[Object] at the cut instead of exhausting the stack or panicking.

Closes boa-dev#5654
Comment on lines 35 to +36
indent: usize,
depth: u32,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing indent and depth seems redundant to me, since you can derive indent from depth i.e, indent = depth * INDENT_SIZE, where INDENT_SIZE is 4.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

2 participants