8000 fix incorrect padding with multibyte strings encryption by fpirsch · Pull Request #1962 · laravel/laravel · GitHub
[go: up one dir, main page]

Skip to content

fix incorrect padding with multibyte strings encryption #1962

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

Merged
merged 1 commit into from
May 14, 2013
Merged
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
18 changes: 3 additions & 15 deletions laravel/crypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected static function iv_size()
*/
protected static function pad($value)
{
$pad = static::$block - (Str::length($value) % static::$block);
$pad = static::$block - (strlen($value) % static::$block);

return $value .= str_repeat(chr($pad), $pad);
}
Expand All @@ -129,14 +129,7 @@ protected static function pad($value)
*/
protected static function unpad($value)
{
if (MB_STRING)
{
$pad = ord(mb_substr($value, -1, 1, Config::get('application.encoding')));
}
else
{
$pad = ord(substr($value, -1));
}
$pad = ord(substr($value, -1));

if ($pad and $pad <= static::$block)
{
Expand All @@ -145,12 +138,7 @@ protected static function unpad($value)
// as the padding appears to have been changed.
if (preg_match('/'.chr($pad).'{'.$pad.'}$/', $value))
{
if (MB_STRING)
{
return mb_substr($value, 0, Str::length($value) - $pad, Config::get('application.encoding'));
}

return substr($value, 0, Str::length($value) - $pad);
return substr($value, 0, strlen($value) - $pad);
}

// If the padding characters do not match the expected padding
Expand Down
0