Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 Fix: Body serialization should respect max_nesting_depth config by AronNovak · Pull Request #661 · rollbar/rollbar-php · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/DataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class DataBuilder implements DataBuilderInterface
protected $captureEmail;
protected $captureUsername;

protected $maxNestingDepth;

/**
* @var Utilities
*/
Expand Down Expand Up @@ -99,6 +101,7 @@ public function __construct(array $config)
$this->setCustom($config);
$this->setFingerprint($config);
$this->setTitle($config);
$this->setMaxNestingDepth($config);
$this->setNotifier($config);
$this->setBaseException($config);
$this->setIncludeCodeContext($config);
Expand Down Expand Up @@ -129,6 +132,12 @@ protected function setCaptureUsername($config)
$fromConfig = $config['capture_username'] ?? null;
$this->captureUsername = self::$defaults->captureUsername($fromConfig);
}

protected function setMaxNestingDepth($config)
{
$fromConfig = $config['max_nesting_depth'] ?? null;
$this->maxNestingDepth = self::$defaults->maxNestingDepth($fromConfig);
}

protected function setEnvironment($config)
{
Expand Down Expand Up @@ -411,7 +420,7 @@ protected function getBody(Throwable|string|Stringable $toLog, array $context):
} else {
$content = $this->getMessage($toLog);
}
return new Body($content, $context, $this->getTelemetry());
return new Body($content, $context, $this->getTelemetry(), $this->maxNestingDepth);
}

public function getErrorTrace(ErrorWrapper $error)
Expand Down
9 changes: 7 additions & 2 deletions src/Payload/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Body implements SerializerInterface
public function __construct(
private ContentInterface $value,
private array $extra = [],
private ?array $telemetry = null
private ?array $telemetry = null,
private int $maxDepth = -1
) {
}

Expand Down Expand Up @@ -122,6 +123,10 @@ public function serialize()
$result['telemetry'] = $this->telemetry;
}

return $this->utilities()->serializeForRollbarInternal($result, array('extra'));
if ($this->maxDepth === -1) {
return $this->utilities()->serializeForRollbarInternal($result, array('extra'));
}
$objectHashes = array();
return $this->utilities()->serializeForRollbar($result, array('extra'), $objectHashes, $this->maxDepth);
}
}
33 changes: 33 additions & 0 deletions tests/BodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,37 @@ public function testSerialize(): void
$encoded
);
}

public function testSerializeWithMaxNestingDepth(): void
{
$value = m::mock(ContentInterface::class)
->shouldReceive("serialize")
->andReturn("{CONTENT}")
->shouldReceive("getKey")
->andReturn("content_interface")
->mock();

// Create deeply nested array that would cause memory issues
$deepArray = array('level1' => array('level2' => array('level3' => array('level4' => 'deep_value'))));

// Test without depth limit - should serialize completely
$bodyNoLimit = new Body($value, array('deep' => $deepArray), null, -1);
$resultNoLimit = $bodyNoLimit->serialize();

// Test with depth limit - should truncate deep nesting
$bodyWithLimit = new Body($value, array('deep' => $deepArray), null, 2);
$resultWithLimit = $bodyWithLimit->serialize();

// Verify basic structure exists
$this->assertArrayHasKey('extra', $resultNoLimit);
$this->assertArrayHasKey('extra', $resultWithLimit);

// Without limit should have all nested levels
$this->assertEquals('deep_value', $resultNoLimit['extra']['deep']['level1']['level2']['level3']['level4']);

// With limit should truncate the 'deep' array due to depth constraint
// At depth 2: root -> extra -> deep (gets truncated to empty array)
$this->assertArrayHasKey('deep', $resultWithLimit['extra']);
$this->assertEmpty($resultWithLimit['extra']['deep']); // Truncated due to depth limit
}
}
0