storj-thirdparty / uplink-php

Uplink library bindings for PHP
MIT License
33 stars 6 forks source link

Error int instead of FFI\CData #26

Closed Erikvv closed 2 years ago

Erikvv commented 2 years ago

Error occurred when Stefan updated nextcloud with Storj as main storage. OS was unchanged.

This shouldn't ever happen.

TypeError: Argument 2 passed to Storj\Uplink\Project::__construct() must be an instance of FFI\CData, int given, called in /var/www/nextcloud/apps/storj/vendor/storj/uplink/src/Access.php on line 67 and defined in /var/www/nextcloud/apps/storj/vendor/storj/uplink/src/Project.php:35
Stack trace:
#0 /var/www/nextcloud/apps/storj/vendor/storj/uplink/src/Access.php(67): Storj\Uplink\Project->__construct()
#1 /var/www/nextcloud/apps/storj/lib/ProjectFactory.php(15): Storj\Uplink\Access->openProject()
#2 /var/www/nextcloud/apps/storj/lib/ProjectFactory.php(16): OCA\Storj\ProjectFactory::OCA\Storj\{closure}()
#3 /var/www/nextcloud/apps/storj/lib/StorjObjectStore.php(33): OCA\Storj\ProjectFactory::fromParams()
#4 /var/www/nextcloud/lib/private/legacy/OC_Util.php(127): OCA\Storj\StorjObjectStore->__construct()
#5 /var/www/nextcloud/lib/private/legacy/OC_Util.php(301): OC_Util::initObjectStoreRootFS()
#6 /var/www/nextcloud/lib/private/Files/Mount/Manager.php(91): OC_Util::setupFS()
#7 /var/www/nextcloud/lib/private/Files/Filesystem.php(334): OC\Files\Mount\Manager->find()
#8 /var/www/nextcloud/lib/private/Files/View.php(1156): OC\Files\Filesystem::resolvePath()
#9 /var/www/nextcloud/lib/private/Files/View.php(601): OC\Files\View->basicOperation()
#10 /var/www/nextcloud/lib/private/Files/Node/File.php(56): OC\Files\View->file_get_contents()
#11 /var/www/nextcloud/lib/private/Files/SimpleFS/SimpleFile.php(90): OC\Files\Node\File->getContent()
#12 /var/www/nextcloud/lib/private/App/AppStore/Fetcher/Fetcher.php(166): OC\Files\SimpleFS\SimpleFile->getContent()
#13 /var/www/nextcloud/lib/private/App/AppStore/Fetcher/AppFetcher.php(186): OC\App\AppStore\Fetcher\Fetcher->get()
#14 /var/www/nextcloud/lib/private/Installer.php(433): OC\App\AppStore\Fetcher\AppFetcher->get()
#15 /var/www/nextcloud/lib/private/Updater.php(413): OC\Installer->isUpdateAvailable()
#16 /var/www/nextcloud/lib/private/Updater.php(274): OC\Updater->upgradeAppStoreApps()
#17 /var/www/nextcloud/lib/private/Updater.php(133): OC\Updater->doUpgrade()
#18 /var/www/nextcloud/core/Command/Upgrade.php(235): OC\Updater->upgrade()
#19 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Upgrade->execute()
#20 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#21 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#22 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#23 /var/www/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#24 /var/www/nextcloud/console.php(99): OC\Console\Application->run()
#25 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
Erikvv commented 2 years ago
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye
$ php --version
PHP 7.4.25 (cli) (built: Oct 23 2021 21:53:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies
$ apt show libffi-dev
Package: libffi-dev
Version: 3.3-6
Priority: optional
Section: libdevel
Source: libffi
Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Installed-Size: 308 kB
Depends: libffi7 (= 3.3-6)
Conflicts: libffi4-dev
(...)
root@nextcloud-web01:/usr/lib# apt show libffi7
Package: libffi7
Version: 3.3-6
Priority: optional
Section: libs
Source: libffi
Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Installed-Size: 67.6 kB
Depends: libc6 (>= 2.14)
(...)

I have inserted the following code at the line before the error occurs:

var_dump($projectResult);
var_dump($projectResult->project);

And this gives the following output:

object(FFI\CData:struct UplinkProjectResult)#5429 (2) {
  ["project"]=>
  object(FFI\CData:struct UplinkProject*)#5426 (1) {
    [0]=>
    object(FFI\CData:struct UplinkProject)#5425 (1) {
      ["_handle"]=>
      int(2)
    }
  }
  ["error"]=>
  NULL
}
object(FFI\CData:struct UplinkProject*)#5426 (1) {
  [0]=>
  object(FFI\CData:struct UplinkProject)#5425 (1) {
    ["_handle"]=>
    int(2)
  }
}

object(FFI\CData:struct UplinkProjectResult)#5403 (2) {
  ["project"]=>
  object(FFI\CData:struct UplinkProject*)#5402 (1) {
    [0]=>
    object(FFI\CData:struct UplinkProject)#5401 (1) {
      ["_handle"]=>
      int(4)
    }
  }
  ["error"]=>
  NULL
}
object(FFI\CData:struct UplinkProject*)#5402 (1) {
  [0]=>
  object(FFI\CData:struct UplinkProject)#5401 (1) {
    ["_handle"]=>
    int(4)
  }
}

object(FFI\CData:struct UplinkProjectResult)#5379 (2) {
  ["project"]=>
  object(FFI\CData:struct UplinkProject*)#5377 (1) {
    [0]=>
    object(FFI\CData:struct UplinkProject)#5378 (1) {
      ["_handle"]=>
      int(6)
    }
  }
  ["error"]=>
  NULL
}
object(FFI\CData:struct UplinkProject*)#5377 (1) {
  [0]=>
  object(FFI\CData:struct UplinkProject)#5378 (1) {
    ["_handle"]=>
    int(6)
  }
}

object(FFI\CData:struct UplinkProjectResult)#5378 (2) {
  ["project"]=>
  object(FFI\CData:struct UplinkProject*)#5374 (1) {
    [0]=>
    object(FFI\CData:struct UplinkProject)#5376 (1) {
      ["_handle"]=>
      int(8)
    }
  }
  ["error"]=>
  NULL
}
object(FFI\CData:struct UplinkProject*)#5374 (1) {
  [0]=>
  object(FFI\CData:struct UplinkProject)#5376 (1) {
    ["_handle"]=>
    int(8)
  }
}

object(FFI\CData:struct UplinkProjectResult)#5375 (2) {
  ["project"]=>
  object(FFI\CData:struct UplinkProject*)#5373 (1) {
    [0]=>
    object(FFI\CData:struct UplinkProject)#5370 (1) {
      ["_handle"]=>
      int(10)
    }
  }
  ["error"]=>
  NULL
}
int(0)

It shows that the line executes 4 times correctly but the 5th time it seems to have an issue dereferencing the pointer and it becomes int(0).

Erikvv commented 2 years ago

I observer that 5375 = 0x14FF which ends in 0b11111111 which may be interpreted as something unexpected.

Erikvv commented 2 years ago

I ran a Debian container with the exact same versions as listed and UplinkProjectResult as object #5375 but I was not able to reproduce the problem.

Erikvv commented 2 years ago

When I a cast to the correct type using FFI::cast("UplinkProject*", $var) I am able to eliminate the problem at the line and the resulting CData object looks OK. However then garbage data pops up later in the code when the object is passed around.

Other things I've tried:

Erikvv commented 2 years ago

After a reinstall of the nextcloud storj app (including this library) things were fine again. I have no actionable items so I will close this issue and keep it in mind if someone reports a similar problem.