Skip to content
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

[BUGFIX] Reliably catch E_WARNING when unserialize() fails #1124

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions Classes/Converter/JsonCompatibilityConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@
public function convert(string $dataString)
{
try {
set_error_handler(function ($severity, $message, $file, $line) {

Check warning on line 40 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "FunctionCallRemoval": --- Original +++ New @@ @@ public function convert(string $dataString) { try { - set_error_handler(function ($severity, $message, $file, $line) { - throw new \ErrorException($message, 0, $severity, $file, $line); - }); + $unserialized = unserialize($dataString, ['allowed_classes' => false]); } catch (\Throwable $e) { $unserialized = false;

Check failure on line 40 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / PHPstan

Parameter #1 $severity of anonymous function has no typehint.

Check failure on line 40 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / PHPstan

Parameter #2 $message of anonymous function has no typehint.

Check failure on line 40 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / PHPstan

Parameter #3 $file of anonymous function has no typehint.

Check failure on line 40 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / PHPstan

Parameter #4 $line of anonymous function has no typehint.
throw new \ErrorException($message, 0, $severity, $file, $line);

Check warning on line 41 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ { try { set_error_handler(function ($severity, $message, $file, $line) { - throw new \ErrorException($message, 0, $severity, $file, $line); + throw new \ErrorException($message, 1, $severity, $file, $line); }); $unserialized = unserialize($dataString, ['allowed_classes' => false]); } catch (\Throwable $e) {

Check warning on line 41 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "Throw_": --- Original +++ New @@ @@ { try { set_error_handler(function ($severity, $message, $file, $line) { - throw new \ErrorException($message, 0, $severity, $file, $line); + new \ErrorException($message, 0, $severity, $file, $line); }); $unserialized = unserialize($dataString, ['allowed_classes' => false]); } catch (\Throwable $e) {

Check warning on line 41 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ { try { set_error_handler(function ($severity, $message, $file, $line) { - throw new \ErrorException($message, 0, $severity, $file, $line); + throw new \ErrorException($message, -1, $severity, $file, $line); }); $unserialized = unserialize($dataString, ['allowed_classes' => false]); } catch (\Throwable $e) {
});
$unserialized = unserialize($dataString, ['allowed_classes' => false]);
} catch (\Throwable $e) {
$unserialized = false;
} finally {

Check warning on line 46 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "Finally_": --- Original +++ New @@ @@ $unserialized = unserialize($dataString, ['allowed_classes' => false]); } catch (\Throwable $e) { $unserialized = false; - } finally { - restore_error_handler(); - } + } if (is_object($unserialized)) { throw new \Exception('Objects are not allowed: ' . var_export($unserialized, true), 1593758307); }
restore_error_handler();

Check warning on line 47 in Classes/Converter/JsonCompatibilityConverter.php

View workflow job for this annotation

GitHub Actions / Mutation tests (7.4, ubuntu-latest)

Escaped Mutant for Mutator "FunctionCallRemoval": --- Original +++ New @@ @@ } catch (\Throwable $e) { $unserialized = false; } finally { - restore_error_handler(); + } if (is_object($unserialized)) { throw new \Exception('Objects are not allowed: ' . var_export($unserialized, true), 1593758307);
}

if (is_object($unserialized)) {
throw new \Exception('Objects are not allowed: ' . var_export($unserialized, true), 1593758307);
}
Expand Down
Loading