Problem/Motivation

The following error keeps appearing in the logs. The issue seems to be coming from the data structure after it has been decrypted.

Steps to reproduce

Run this test

../vendor/bin/phpunit -c core ./modules/contrib/bakery/tests/src/Unit/KitchenTest.php

Example error

unserialize(): Extra data starting at offset 161 of 176 bytes

Proposed resolution

Right trim the decrypt string in function before it's unserialized

  public function decrypt(string $text): string {
    .....
    return rtrim($data, "\0");//$data; <---- replace $data with rtrim($data, "\0");
  }

Issue fork bakery-3526876

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

purencool created an issue. See original summary.

avpaderno’s picture

It seems the used library adds extra NULL characters. See phpseclib_mcrypt_generic_helper(), the helper function called by other functions (phpseclib_mdecrypt_generic(), for example.)

    function phpseclib_mcrypt_generic_helper(Base $td, &$data, $op)
    {
        // phpseclib does not currently provide a way to retrieve the mode once it has been set via "public" methods
        if (phpseclib_mcrypt_enc_is_block_mode($td)) {
            $block_length = phpseclib_mcrypt_enc_get_iv_size($td);
            $extra = strlen($data) % $block_length;
            if ($extra) {
                $data.= str_repeat("\0", $block_length - $extra);
            }
        }

avpaderno’s picture

Status: Active » Needs review
purencool’s picture

Status: Needs review » Reviewed & tested by the community

purencool’s picture

Before merge

PHPUnit 9.6.23 by Sebastian Bergmann and contributors.

Testing /var/www/html/web/modules/contrib/bakery/tests
EEI.E.EEE.I.....................E....E.E..I.

After merge

PHPUnit 9.6.23 by Sebastian Bergmann and contributors.

Testing /var/www/html/web/modules/contrib/bakery/tests
..I.......I...............................I.                      44 / 44 (100%)
purencool’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.