[Bugfix][Multimodal] Reject malformed base64 audio with 400 instead of 500 (#53744)

Signed-off-by: mhuzaifa3 <mhuzaifa3@outlook.com>

Moe Huzaifa committed Aug 25, 2026 at 12:31 UTC 299ebd094a9cea1a16077dc2a4419192b85a777c
2 files changed +13 -1
tests/multimodal/media/test_audio.py
+12
@@ -46,6 +46,18 @@ def test_audio_media_io_load_base64(dummy_audio_bytes):
46 assert out[1] == 16000
47
48
49 +def test_audio_media_io_load_base64_rejects_malformed(dummy_audio_bytes):
50 + """Malformed base64 must surface as a ValueError so the server answers 400.
51 + Without strict decoding the bad characters are dropped, the garbage reaches
52 + libsndfile, and the client gets a 500 instead."""
53 + encoded = base64.b64encode(dummy_audio_bytes).decode("utf-8")
54 + malformed = encoded[:8] + "!!!@@@###" + encoded[8:]
55 +
56 + audio_io = AudioMediaIO()
57 + with pytest.raises(ValueError):
58 + audio_io.load_base64("audio/wav", malformed)
59 +
60 +
61 def test_audio_media_io_load_file(audio_assets: AudioTestAssets):
62 audio_io = AudioMediaIO()
63 path = audio_assets[0].get_local_path()
vllm/multimodal/media/audio.py
+1 -1
@@ -309,7 +309,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
309 parameter="audio_filesize_mb",
310 value=(len(data) * 3 / 4) / MiB_bytes,
311 )
312 - return self.load_bytes(pybase64.b64decode(data))
312 + return self.load_bytes(pybase64.b64decode(data, validate=True))
313
314 def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
315 self._validate_encoded_size(filepath.stat().st_size)