openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix: add max size check on audio base64 input (closes #1944)

Open PranavAgarkar07 opened this issue 6 months ago β€’ 1 comments

Summary

Add a maximum size guard on base64-encoded audio input before decoding to prevent OOM on excessively large payloads.

Changes

  • Added MAX_AUDIO_BASE64_LEN constant (33,554,432 bytes = 32 MiB of base64 text β‰ˆ 24 MiB decoded)
  • Added early-return guard before BASE64.decode() in cloud_transcribe.rs
  • Returns friendly error message when limit is exceeded

Checklist

  • [x] cargo check passes
  • [x] cargo fmt --check passes

Summary by CodeRabbit

  • Bug Fixes
    • Cloud transcription now validates audio file size and rejects oversized requests with a clear error message, preventing upload issues.

Review Change Stack

PranavAgarkar07 avatar May 16 '26 15:05 PranavAgarkar07

πŸ“ Walkthrough

Walkthrough

This PR adds a size validation gate to the voice transcription pipeline. A new constant MAX_AUDIO_BASE64_LEN defines the maximum base64 input size, and the transcribe_cloud function now rejects requests with oversized payloads before attempting to decode or upload.

Changes

Audio payload size validation

Layer / File(s) Summary
Audio payload size limit and validation
src/openhuman/voice/cloud_transcribe.rs
MAX_AUDIO_BASE64_LEN constant defines the payload ceiling, and transcribe_cloud validates the trimmed audio_base64 length and rejects oversized inputs with a formatted error before any decode step.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

  • tinyhumansai/openhuman#1944: Directly implements the same MAX_AUDIO_BASE64_LEN size validation and pre-decode length check in transcribe_cloud.

Poem

🐰 A bunny guards the audio gate, Measuring base64 before it's too late, No oversized payloads shall pass through today, Just gentle validation to keep chaos at bay! 🎀✨

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly summarizes the main change: adding a maximum size check on audio base64 input, which matches the primary objective of the PR.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 16 '26 15:05 coderabbitai[bot]