From b271cd4294a2fb19f18d9f0fd0284f224b3e9d28 Mon Sep 17 00:00:00 2001 From: Garrick Lam Date: Thu, 3 Oct 2019 13:02:02 +0800 Subject: [PATCH] Don't even try to attempt normalizing iterators or generators in context Iterators and Generators may not be rewindable, so foreach is not safe to use on them. Iterators and especially Generators may trigger irreversible actions on calling next(), so iterating over all values can potentially cause harm, e.g. imagine an iterator over a set of HTTP POST requests that are sent when the next value is requested . The only sufficiently safe thing to iterate and include here are primitive arrays. --- src/Monolog/Formatter/JsonFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index 2ff119ea..8d10b825 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -145,7 +145,7 @@ class JsonFormatter extends NormalizerFormatter return 'Over 9 levels deep, aborting normalization'; } - if (is_array($data) || $data instanceof \Traversable) { + if (is_array($data)) { $normalized = array(); $count = 1;