[GH-ISSUE #2324] [Issue]: TTS speak() buffers the entire provider response into memory before enforcing the 20MB cap #1151

Closed
opened 2026-10-21 05:27:59 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2324

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — Unbounded buffering / DoS. TTS speak() reads the entire provider response body into memory with response.bytes().await before the 20 MB cap is checked, so the cap cannot prevent a memory blow-up. A misbehaving/hostile TTS endpoint can stream a multi-GB body (within the up-to-30-minute request timeout) and OOM the process before the limit fires.

Expected behavior

The body should be streamed with a running byte counter and aborted once MAX_TTS_AUDIO_BYTES (20 MB) is exceeded, and/or a Content-Length pre-check applied before downloading — mirroring the established pattern in custom_tools.rs.

Actual behavior

src-tauri/src/commands/storage/integrations/tts.rs:425-447:

let bytes = response
    .bytes()
    .await
    .map_err(|error| AppError::new("tts_response_error", error.to_string()))?;
...
if bytes.len() > MAX_TTS_AUDIO_BYTES {
    return Err(AppError::invalid_input("TTS audio response is too large"));
}

The whole body is buffered first; the cap at line 445 runs after. There is no Content-Length pre-check and no streaming counter. The request timeout is configurable up to 30 minutes (MAX_TTS_REQUEST_TIMEOUT_MS = 30 * 60_000). The codebase already does this correctly elsewhere: custom_tools.rs:287-300 has a content_length() pre-check plus a .chunk() loop with a running counter; the TTS path has neither.

Steps to reproduce

  1. Configure a TTS source pointing at an endpoint that returns a multi-GB body with an audio content-type.
  2. Call tts/speak.
  3. The full body buffers into memory before the 20 MB check; large enough bodies OOM the process.

Impact area

  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (also server mode)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: TTS source

Logs, screenshots, or video

Static source audit; cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main. TTS config comes from stored app-settings (not the per-request body), so exploitation requires a hostile/broken user-chosen endpoint (desktop) or a post-auth config write (server), hence low.

Additional context

Suggested fix: add a response.content_length() pre-check before download and replace bytes().await with a .chunk() loop carrying a running counter that aborts once MAX_TTS_AUDIO_BYTES is exceeded, mirroring custom_tools.rs. (images/providers.rs:474 shares the same weakness and could be fixed alongside.)

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2324 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — Unbounded buffering / DoS.** TTS `speak()` reads the entire provider response body into memory with `response.bytes().await` before the 20 MB cap is checked, so the cap cannot prevent a memory blow-up. A misbehaving/hostile TTS endpoint can stream a multi-GB body (within the up-to-30-minute request timeout) and OOM the process before the limit fires. ## Expected behavior The body should be streamed with a running byte counter and aborted once `MAX_TTS_AUDIO_BYTES` (20 MB) is exceeded, and/or a `Content-Length` pre-check applied before downloading — mirroring the established pattern in `custom_tools.rs`. ## Actual behavior `src-tauri/src/commands/storage/integrations/tts.rs:425-447`: ```rust let bytes = response .bytes() .await .map_err(|error| AppError::new("tts_response_error", error.to_string()))?; ... if bytes.len() > MAX_TTS_AUDIO_BYTES { return Err(AppError::invalid_input("TTS audio response is too large")); } ``` The whole body is buffered first; the cap at line 445 runs after. There is no `Content-Length` pre-check and no streaming counter. The request timeout is configurable up to 30 minutes (`MAX_TTS_REQUEST_TIMEOUT_MS = 30 * 60_000`). The codebase already does this correctly elsewhere: `custom_tools.rs:287-300` has a `content_length()` pre-check plus a `.chunk()` loop with a running counter; the TTS path has neither. ## Steps to reproduce 1. Configure a TTS source pointing at an endpoint that returns a multi-GB body with an audio content-type. 2. Call `tts/speak`. 3. The full body buffers into memory before the 20 MB check; large enough bodies OOM the process. ## Impact area - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (also server mode) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: TTS source ## Logs, screenshots, or video Static source audit; cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. TTS config comes from stored app-settings (not the per-request body), so exploitation requires a hostile/broken user-chosen endpoint (desktop) or a post-auth config write (server), hence low. ## Additional context Suggested fix: add a `response.content_length()` pre-check before download and replace `bytes().await` with a `.chunk()` loop carrying a running counter that aborts once `MAX_TTS_AUDIO_BYTES` is exceeded, mirroring `custom_tools.rs`. (`images/providers.rs:474` shares the same weakness and could be fixed alongside.) ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:27:59 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2401, merged into refactor.

<!-- gh-comment-id:4637950792 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2401, merged into `refactor`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1151
No description provided.