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

This commit is contained in:
mateo-berri 2026-08-29 11:41:24 -07:00
parent 676f841534
commit 7c4cf2dcff
2 changed files with 2 additions and 2 deletions

View file

@ -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,

View file

@ -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"):