Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/multimodal/media/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def test_audio_media_io_load_base64(dummy_audio_bytes):
assert out[1] == 16000


def test_audio_media_io_load_base64_rejects_malformed(dummy_audio_bytes):
"""Malformed base64 must surface as a ValueError so the server answers 400.
Without strict decoding the bad characters are dropped, the garbage reaches
libsndfile, and the client gets a 500 instead."""
encoded = base64.b64encode(dummy_audio_bytes).decode("utf-8")
malformed = encoded[:8] + "!!!@@@###" + encoded[8:]

audio_io = AudioMediaIO()
with pytest.raises(ValueError):
audio_io.load_base64("audio/wav", malformed)


def test_audio_media_io_load_file(audio_assets: AudioTestAssets):
audio_io = AudioMediaIO()
path = audio_assets[0].get_local_path()
Expand Down
2 changes: 1 addition & 1 deletion vllm/multimodal/media/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def load_base64(
parameter="audio_filesize_mb",
value=(len(data) * 3 / 4) / MiB_bytes,
)
return self.load_bytes(pybase64.b64decode(data))
return self.load_bytes(pybase64.b64decode(data, validate=True))

def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
self._validate_encoded_size(filepath.stat().st_size)
Expand Down
Loading