Skip to content

Commit a35e40c

Browse files
alehonicolas-grekas
authored andcommitted
[ErrorHandler] Don't format binary strings
Calling var_export on a binary string easily causes memory exhaustion if it's called with even a small image. Fixes #53005
1 parent 4ced0e9 commit a35e40c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Extension/CodeExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ public function formatArgs(array $args): string
9797
$formattedValue = '<em>'.strtolower(htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset)).'</em>';
9898
} elseif ('resource' === $item[0]) {
9999
$formattedValue = '<em>resource</em>';
100+
} elseif (preg_match('/[^\x07-\x0D\x1B\x20-\xFF]/', $item[1])) {
101+
$formattedValue = '<em>binary string</em>';
100102
} else {
101-
$formattedValue = str_replace("\n", '', htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset));
103+
$formattedValue = str_replace("\n", '', $this->escape(var_export($item[1], true)));
102104
}
103105

104106
$result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", htmlspecialchars($key, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $formattedValue);

0 commit comments

Comments
 (0)