Files
Ferdinand Thiessen 20e0f74074 fix(encryption): use the block size of the file encoding when fixing sizes
`fixUnencryptedSize()` asked the encryption module for the unencrypted
block size before calling `begin()`. The module only learns the encoding
of the file (binary or legacy base64) from the header in `begin()`, so
the block size of binary encoded files was used for legacy base64 files.

This stored an inflated unencrypted size for legacy files, which then
breaks downloads: the announced content length is too large and the
signature check of the last block fails with "Bad Signature".

Fixes #63662

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-10-14 09:51:46 +02:00

52 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Testing\Command;
use OCP\Files\IRootFolder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Overwrite the unencrypted size stored in the file cache, e.g. to simulate
* file cache entries written by older versions.
*/
class SetUnencryptedSize extends Command {
public function __construct(
private IRootFolder $rootFolder,
) {
parent::__construct();
}
#[\Override]
protected function configure(): void {
$this
->setName('testing:set-unencrypted-size')
->setDescription('Overwrite the unencrypted size of a file in the file cache')
->addArgument('user', InputArgument::REQUIRED, 'Owner of the file')
->addArgument('path', InputArgument::REQUIRED, 'Path of the file relative to the home of the user')
->addArgument('size', InputArgument::REQUIRED, 'Unencrypted size to store');
}
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$node = $this->rootFolder
->getUserFolder($input->getArgument('user'))
->get($input->getArgument('path'));
$node->getStorage()->getCache()->update($node->getId(), [
'unencrypted_size' => (int)$input->getArgument('size'),
]);
return self::SUCCESS;
}
}