From d44db887870431e88f8cb386be9a3cd112ca65e1 Mon Sep 17 00:00:00 2001 From: Mathias Date: Sat, 3 Oct 2026 20:56:37 +0200 Subject: [PATCH] test(audio): ffprobe output past a cap is unreadable, not buffered (#49), red Co-Authored-By: Claude Sonnet 5.5 --- internal/adapters/audio/ffprobe_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/adapters/audio/ffprobe_test.go b/internal/adapters/audio/ffprobe_test.go index 5190abb..cc3fa68 100644 --- a/internal/adapters/audio/ffprobe_test.go +++ b/internal/adapters/audio/ffprobe_test.go @@ -215,3 +215,22 @@ func TestFFprobeProbe_AsksOnlyForTheFieldsParseProbeReads(t *testing.T) { require.GreaterOrEqual(t, se, 0, "argv: %v", args) assert.Equal(t, "format=duration:stream=codec_type:stream_disposition=attached_pic", args[se+1]) } + +func TestFFprobeProbe_OutputPastTheCapIsUnreadableNotBuffered(t *testing.T) { + // ffprobe's stdout is attacker-influenced (tags, 491 MB observed). Past the cap the + // probe is stopped and the file is reported as unreadable (#49). + bin := stub(t, `head -c 200000 /dev/zero | tr '\0' 'a'`) + + _, err := (&audio.FFprobe{Bin: bin, MaxOutput: 4096}).Probe(context.Background(), "/x") + + assert.ErrorIs(t, err, uploads.ErrUnreadable) +} + +func TestFFprobeProbe_OutputWithinTheCapIsParsed(t *testing.T) { + bin := stub(t, `echo '{"streams":[{"codec_type":"audio"}],"format":{"duration":"90"}}'`) + + got, err := (&audio.FFprobe{Bin: bin, MaxOutput: 4096}).Probe(context.Background(), "/x") + + require.NoError(t, err) + assert.True(t, got.HasAudio) +}