From f8b845916982cc137e54fbbe0727fa96c3f6d776 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 13 Jan 2026 13:01:17 +0100 Subject: [PATCH 1/2] fix(TextToImageProvider): Use ProcessingException instead of RuntimeException Signed-off-by: Marcel Klehr --- lib/TaskProcessing/TextToImageProvider.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/TaskProcessing/TextToImageProvider.php b/lib/TaskProcessing/TextToImageProvider.php index eb80f454..c42954b7 100644 --- a/lib/TaskProcessing/TextToImageProvider.php +++ b/lib/TaskProcessing/TextToImageProvider.php @@ -15,11 +15,11 @@ use OCP\IAppConfig; use OCP\IL10N; use OCP\TaskProcessing\EShapeType; +use OCP\TaskProcessing\Exception\ProcessingException; use OCP\TaskProcessing\ISynchronousProvider; use OCP\TaskProcessing\ShapeDescriptor; use OCP\TaskProcessing\TaskTypes\TextToImage; use Psr\Log\LoggerInterface; -use RuntimeException; class TextToImageProvider implements ISynchronousProvider { @@ -108,7 +108,7 @@ public function process(?string $userId, array $input, callable $reportProgress) $startTime = time(); if (!isset($input['input']) || !is_string($input['input'])) { - throw new RuntimeException('Invalid prompt'); + throw new ProcessingException('Invalid prompt'); } $prompt = $input['input']; @@ -117,11 +117,23 @@ public function process(?string $userId, array $input, callable $reportProgress) $nbImages = $input['numberOfImages']; } + if ($nbImages > 12) { + throw new ProcessingException('numberOfImages is out of bounds'); + } + if ($nbImages < 1) { + throw new ProcessingException('numberOfImages is out of bounds'); + } + $size = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size', lazy: true) ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; if (isset($input['size']) && is_string($input['size']) && preg_match('/^\d+x\d+$/', $input['size'])) { $size = trim($input['size']); } + [$x, $y] = explode('x', $size, 2); + if ((int)$x > 4096 || (int)$y > 4096) { + throw new ProcessingException('size is out of bounds'); + } + if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { @@ -148,7 +160,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (empty($urls) && empty($b64s)) { $this->logger->warning('OpenAI/LocalAI\'s text to image generation failed: no image returned'); - throw new RuntimeException('OpenAI/LocalAI\'s text to image generation failed: no image returned'); + throw new ProcessingException('OpenAI/LocalAI\'s text to image generation failed: no image returned'); } $client = $this->clientService->newClient(); $requestOptions = $this->openAiAPIService->getImageRequestOptions($userId); @@ -167,7 +179,7 @@ public function process(?string $userId, array $input, callable $reportProgress) return $output; } catch (\Exception $e) { $this->logger->warning('OpenAI/LocalAI\'s text to image generation failed with: ' . $e->getMessage(), ['exception' => $e]); - throw new RuntimeException('OpenAI/LocalAI\'s text to image generation failed with: ' . $e->getMessage()); + throw new ProcessingException('OpenAI/LocalAI\'s text to image generation failed with: ' . $e->getMessage()); } } } From 1dde3dd34fcbd8baef7effd645d1e9320e0ca49c Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 14 Jan 2026 09:47:48 +0100 Subject: [PATCH 2/2] fix: Apply suggestions from code review Signed-off-by: Marcel Klehr --- lib/TaskProcessing/TextToImageProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/TaskProcessing/TextToImageProvider.php b/lib/TaskProcessing/TextToImageProvider.php index c42954b7..b9b0e31f 100644 --- a/lib/TaskProcessing/TextToImageProvider.php +++ b/lib/TaskProcessing/TextToImageProvider.php @@ -118,10 +118,10 @@ public function process(?string $userId, array $input, callable $reportProgress) } if ($nbImages > 12) { - throw new ProcessingException('numberOfImages is out of bounds'); + throw new ProcessingException('numberOfImages is out of bounds: Cannot generate more than 12 images'); } if ($nbImages < 1) { - throw new ProcessingException('numberOfImages is out of bounds'); + throw new ProcessingException('numberOfImages is out of bounds: Cannot generate less than 1 image'); } $size = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size', lazy: true) ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; @@ -131,7 +131,7 @@ public function process(?string $userId, array $input, callable $reportProgress) [$x, $y] = explode('x', $size, 2); if ((int)$x > 4096 || (int)$y > 4096) { - throw new ProcessingException('size is out of bounds'); + throw new ProcessingException('size is out of bounds: should be within 4096x4096'); } if (isset($input['model']) && is_string($input['model'])) {