diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index 502f3ae09c82..af075a31e713 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -284,7 +284,13 @@ public function valid_base64($str = null): bool $str = (string) $str; } - return base64_encode(base64_decode($str, true)) === $str; + $decoded = base64_decode($str, true); + + if ($decoded === false) { + return false; + } + + return base64_encode($decoded) === $str; } /** diff --git a/tests/system/Validation/FormatRulesTest.php b/tests/system/Validation/FormatRulesTest.php index 7849ad3afd4c..0b4dc2151d9e 100644 --- a/tests/system/Validation/FormatRulesTest.php +++ b/tests/system/Validation/FormatRulesTest.php @@ -1053,6 +1053,10 @@ public static function provideBase64(): iterable 'FA08GG', false, ], + [ + 'dGVszdA==', + false, + ], [ null, false, diff --git a/user_guide_src/source/changelogs/v4.6.4.rst b/user_guide_src/source/changelogs/v4.6.4.rst index 116c371d10c2..98dba2bff6d5 100644 --- a/user_guide_src/source/changelogs/v4.6.4.rst +++ b/user_guide_src/source/changelogs/v4.6.4.rst @@ -44,6 +44,7 @@ Bugs Fixed - **Forge:** Fixed a bug in ``Postgre`` and ``SQLSRV`` where changing a column's default value using ``Forge::modifyColumn()`` method produced incorrect SQL syntax. - **Model:** Fixed a bug in ``Model::replace()`` where ``created_at`` field (when available) wasn't set correctly. - **Model:** Fixed a bug in ``Model::insertBatch()`` and ``Model::updateBatch()`` where casts were not applied to inserted or updated values. +- **Validation:** Fixed a bug in the ``FormatRules::valid_base64()`` validation rule that caused a TypeError when checking invalid base64 strings. See the repo's `CHANGELOG.md `_