Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(mistral): reject malformed base64 audio_data with strict validation

mateo-berri7c4cf2dcffbb
diff --git a/litellm/llms/mistral/audio_speech/transformation.py b/litellm/llms/mistral/audio_speech/transformation.py
index 6d1a693268a..e7f7d510346 100644
--- a/litellm/llms/mistral/audio_speech/transformation.py
+++ b/litellm/llms/mistral/audio_speech/transformation.py
@@ -172,7 +172,7 @@ class MistralTextToSpeechConfig(BaseTextToSpeechConfig):
headers=raw_response.headers,
)
try:
- audio_bytes: Final = base64.b64decode(audio_b64)
+ audio_bytes: Final = base64.b64decode(audio_b64, validate=True)
except ValueError:
raise MistralTextToSpeechException(
status_code=500,
diff --git a/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py b/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
index 20d07699cb8..6d250901e50 100644
--- a/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
+++ b/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
@@ -187,7 +187,7 @@ def test_transform_response_invalid_base64_raises():
config: Final = MistralTextToSpeechConfig()
raw_response: Final = httpx.Response(
status_code=200,
- json={"audio_data": "!!!not-base64!!!"},
+ json={"audio_data": "QUJD!QUJD"},
request=httpx.Request("POST", SPEECH_URL),
)
with pytest.raises(MistralTextToSpeechException, match="base64"):