LocalAI/core
Attila Györffy 5a67b5d73c
Fix image upload processing and img2img pipeline in diffusers backend (#8879)
* fix: add missing bufio.Flush in processImageFile

The processImageFile function writes decoded image data (from base64
or URL download) through a bufio.NewWriter but never calls Flush()
before closing the underlying file. Since bufio's default buffer is
4096 bytes, small images produce 0-byte files and large images are
truncated — causing PIL to fail with "cannot identify image file".

This breaks all image input paths: file, files, and ref_images
parameters in /v1/images/generations, making img2img, inpainting,
and reference image features non-functional.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* fix: merge options into kwargs in diffusers GenerateImage

The GenerateImage method builds a local `options` dict containing the
source image (PIL), negative_prompt, and num_inference_steps, but
never merges it into `kwargs` before calling self.pipe(**kwargs).
This causes img2img to fail with "Input is in incorrect format"
because the pipeline never receives the image parameter.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: add unit test for processImageFile base64 decoding

Verifies that a base64-encoded PNG survives the write path
(encode → decode → bufio.Write → Flush → file on disk) with
byte-for-byte fidelity. The test image is small enough to fit
entirely in bufio's 4096-byte buffer, which is the exact scenario
where the missing Flush() produced a 0-byte file.

Also tests that invalid base64 input is handled gracefully.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: verify GenerateImage merges options into pipeline kwargs

Mocks the diffusers pipeline and calls GenerateImage with a source
image and negative prompt. Asserts that the pipeline receives the
image, negative_prompt, and num_inference_steps via kwargs — the
exact parameters that were silently dropped before the fix.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* fix: move kwargs.update(options) earlier in GenerateImage

Move the options merge right after self.options merge (L742) so that
image, negative_prompt, and num_inference_steps are available to all
downstream code paths including img2vid and txt2vid.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: convert processImageFile tests to ginkgo

Replace standard testing with ginkgo/gomega to be consistent with
the rest of the test suites in the project.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

---------

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>
Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
2026-03-11 08:05:50 +01:00
..
application feat(ui): MCP Apps, mcp streaming and client-side support (#8947) 2026-03-11 07:30:49 +01:00
backend feat(functions): add peg-based parsing and allow backends to return tool calls directly (#8838) 2026-03-08 22:21:57 +01:00
cli chore: Standardize CLI flag naming to kebab-case (M12) (#8912) 2026-03-09 22:15:39 +01:00
clients feat(store): add Golang client (#1977) 2024-04-16 15:54:14 +02:00
config feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
dependencies_manager feat(ui): move to React for frontend (#8772) 2026-03-05 21:47:12 +01:00
explorer feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
gallery chore(size): display size of HF models and allow to specify it from the gallery (#8907) 2026-03-09 17:38:14 +01:00
http Fix image upload processing and img2img pipeline in diffusers backend (#8879) 2026-03-11 08:05:50 +01:00
p2p feat(mlx-distributed): add new MLX-distributed backend (#8801) 2026-03-09 17:29:32 +01:00
schema feat(ui): MCP Apps, mcp streaming and client-side support (#8947) 2026-03-11 07:30:49 +01:00
services feat(ui): add canvas mode, support history in agent chat (#8927) 2026-03-09 23:42:47 +01:00
startup feat(api): Add transcribe response format request parameter & adjust STT backends (#8318) 2026-02-01 17:33:17 +01:00
templates chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
trace feat(traces): Add backend traces (#8609) 2026-02-20 23:47:33 +01:00