diff options
author | Nils Adermann <naderman@naderman.de> | 2016-11-24 17:28:53 +0100 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2016-11-24 17:38:07 +0100 |
commit | 45de570954c570deb66686f06da9854ea361779f (patch) | |
tree | 8285bc8a6bffd3facb181c5cf5e3905b4907c4f5 /src | |
parent | 3c782662f9d29c02eb3f200a02dafc8288e28a9e (diff) | |
download | monolog-45de570954c570deb66686f06da9854ea361779f.zip monolog-45de570954c570deb66686f06da9854ea361779f.tar.gz monolog-45de570954c570deb66686f06da9854ea361779f.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Monolog/Formatter/NormalizerFormatter.php | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index f037d54..d441488 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -70,17 +70,13 @@ class NormalizerFormatter implements FormatterInterface return $data; } - if (is_array($data) || $data instanceof \Traversable) { + if (is_array($data)) { $normalized = array(); $count = 1; - if ($data instanceof \Generator && !$data->valid()) { - return array('...' => 'Generator is already consumed, aborting'); - } - foreach ($data as $key => $value) { if ($count++ >= 1000) { - $normalized['...'] = 'Over 1000 items ('.($data instanceof \Generator ? 'generator function' : count($data).' total').'), aborting normalization'; + $normalized['...'] = 'Over 1000 items ('.count($data).' total), aborting normalization'; break; } $normalized[$key] = $this->normalize($value); |