Skip to content

Commit a022c90

Browse files
authored
fix: TypeError in valid_base64 rule when checking invalid base64 strings (#9733)
1 parent 3f3df0d commit a022c90

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

system/Validation/FormatRules.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ public function valid_base64($str = null): bool
284284
$str = (string) $str;
285285
}
286286

287-
return base64_encode(base64_decode($str, true)) === $str;
287+
$decoded = base64_decode($str, true);
288+
289+
if ($decoded === false) {
290+
return false;
291+
}
292+
293+
return base64_encode($decoded) === $str;
288294
}
289295

290296
/**

tests/system/Validation/FormatRulesTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,10 @@ public static function provideBase64(): iterable
10571057
'FA08GG',
10581058
false,
10591059
],
1060+
[
1061+
'dGVszdA==',
1062+
false,
1063+
],
10601064
[
10611065
null,
10621066
false,

user_guide_src/source/changelogs/v4.6.4.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Bugs Fixed
4444
- **Forge:** Fixed a bug in ``Postgre`` and ``SQLSRV`` where changing a column's default value using ``Forge::modifyColumn()`` method produced incorrect SQL syntax.
4545
- **Model:** Fixed a bug in ``Model::replace()`` where ``created_at`` field (when available) wasn't set correctly.
4646
- **Model:** Fixed a bug in ``Model::insertBatch()`` and ``Model::updateBatch()`` where casts were not applied to inserted or updated values.
47+
- **Validation:** Fixed a bug in the ``FormatRules::valid_base64()`` validation rule that caused a TypeError when checking invalid base64 strings.
4748

4849
See the repo's
4950
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)