Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] LoggerDataCollector crashes on empty deprecation.log #31050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
althaus opened this issue Apr 10, 2019 · 4 comments
Closed

[HttpKernel] LoggerDataCollector crashes on empty deprecation.log #31050

althaus opened this issue Apr 10, 2019 · 4 comments

Comments

@althaus
Copy link
Contributor

althaus commented Apr 10, 2019

Symfony version(s) affected: 4.2.x

Description

We encountered an issue with the LoggerDataCollector resulting in an error. We simply had an empty (aka zero bytes) deprecation.log file.

 PHP Fatal error: Uncaught ErrorException: Warning: Invalid argument supplied for foreach() in ./vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php:132

 Stack trace:
 #0 ./web/vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php(67): Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector-getContainerDeprecationLogs()
 #1 ./web/vendor/symfony/http-kernel/Profiler/Profiler.php(99): Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector-lateCollect()
 #2 ./web/vendor/symfony/http-kernel/EventListener/ProfilerListener.php(113): Symfony\Component\HttpKernel\Profiler\Profiler-saveProfile(Object(Symfony\Component\HttpKernel\Profiler\Profile))
 #3 ./web/vendor/symfony/event-dispatcher/Debug/WrappedListener.php(115): Symfony\Component\HttpKernel\EventListener\ProfilerListener-onKernelTerminate(Object(Symfony\Component\HttpKernel\Event\PostResponseEvent), 'kernel.terminat...', Object(Symfony\Component\HttpKernel\Debug\ in ./web/vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php on line 132

The reason is the direct unserialization of the file's content. There's just a check if the file exists:

foreach (unserialize(file_get_contents($file)) as $log) {

How to reproduce

Touching deprecation.log in you log directory should be enough to enforce this.

Possible Solution

Extend the check if the file is not empty or the unserialized content is iterable?

Cheers
Matthias

@nicolas-grekas
Copy link
Member

Could you please send a PR fixing the issue?

@althaus
Copy link
Contributor Author

althaus commented Apr 10, 2019

@nicolas-grekas Sure, what'd be your preferred solution? And what should be done if the check fails? Just silently do nothing?

@nicolas-grekas
Copy link
Member

Ignoring silently looks fine to me.

@althaus
Copy link
Contributor Author

althaus commented Apr 11, 2019

Making the fabbot happy takes longer than @nicolas-grekas to review the change. 😁

nicolas-grekas pushed a commit to althaus/symfony that referenced this issue Apr 11, 2019
nicolas-grekas added a commit that referenced this issue Apr 11, 2019
…ile (althaus)

This PR was submitted for the 4.2 branch but it was merged into the 3.4 branch instead (closes #31076).

Discussion
----------

[HttpKernel] Fixed LoggerDataCollector crashing on empty file

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31050
| License       | MIT

This PR adds a check to the LoggerDataCollector if there's acutal some content in the log file.

Commits
-------

291c73a Catch empty deprecation.log silently (fixes #31050)
nicolas-grekas added a commit that referenced this issue Apr 11, 2019
* 3.4:
  Catch empty deprecation.log silently (fixes #31050)
nicolas-grekas added a commit that referenced this issue Apr 11, 2019
* 4.2:
  Catch empty deprecation.log silently (fixes #31050)
  minor: the meaning of the data breach was not correct
  Optimize SVGs
  property normalizer should also pass format and context to isAllowedAttribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants