commit 834c5174b806191e83cf4c7fcf8d72ce8a86c680
parent 4ac2f1f7ae4d7b0f02ceb52b15f9b5d1c724a7c4
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Mon, 23 Oct 2023 08:49:09 +0800
test: expect error for corrupt data
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/internal/test/audio_test.go b/internal/test/audio_test.go
@@ -15,6 +15,8 @@ var (
compressed []byte
//go:embed uncompressed.s16le.pcm
uncompressed []byte
+ //go:embed corrupt.m4a
+ corrupt []byte
)
// TestLoad ensures that output from the native decoders are close to
@@ -71,6 +73,16 @@ func TestDecode(t *testing.T) {
}
}
+// TestDecodeCorrupt ensures that we get an error value on invalid input and
+// that we don't crash the process.
+func TestDecodeCorrupt(t *testing.T) {
+ _, f, err := nativeaudio.Decode(corrupt)
+ if err == nil {
+ t.Fatalf("expected error for corrupt audio data, got nil")
+ }
+ t.Logf("format: %+v", f)
+}
+
// equal decodes the PCM samples and tests if they are "close enough"
// using a heuristic tolerance.
//
diff --git a/internal/test/corrupt.m4a b/internal/test/corrupt.m4a
Binary files differ.