From 442cfdd14ea01f8c9d494d544213b40dc696841f Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sun, 5 Mar 2023 00:29:24 -0800
Subject: Make sure the fmt chunk is large enough

---
 examples/alplay.c       | 2 +-
 examples/alstream.c     | 2 +-
 examples/alstreamcb.cpp | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

(limited to 'examples')

diff --git a/examples/alplay.c b/examples/alplay.c
index e477df28..6f6c8699 100644
--- a/examples/alplay.c
+++ b/examples/alplay.c
@@ -122,7 +122,7 @@ static ALuint LoadSound(const char *filename)
         /* If there's an issue getting the chunk or block alignment, load as
          * 16-bit and have libsndfile do the conversion.
          */
-        if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR)
+        if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR || inf.datalen < 14)
             sample_format = Int16;
         else
         {
diff --git a/examples/alstream.c b/examples/alstream.c
index b561406c..e89481b1 100644
--- a/examples/alstream.c
+++ b/examples/alstream.c
@@ -185,7 +185,7 @@ static int OpenPlayerFile(StreamPlayer *player, const char *filename)
         /* If there's an issue getting the chunk or block alignment, load as
          * 16-bit and have libsndfile do the conversion.
          */
-        if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR)
+        if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR || inf.datalen < 14)
             player->sample_type = Int16;
         else
         {
diff --git a/examples/alstreamcb.cpp b/examples/alstreamcb.cpp
index 994a9c97..c7ebcbe3 100644
--- a/examples/alstreamcb.cpp
+++ b/examples/alstreamcb.cpp
@@ -157,9 +157,9 @@ struct StreamPlayer {
         int splblocksize{}, byteblocksize{};
         if(mSampleFormat == SampleType::IMA4 || mSampleFormat == SampleType::MSADPCM)
         {
-            SF_CHUNK_INFO inf{ "fmt ", 4, 0, NULL };
+            SF_CHUNK_INFO inf{ "fmt ", 4, 0, nullptr };
             SF_CHUNK_ITERATOR *iter = sf_get_chunk_iterator(mSndfile, &inf);
-            if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR)
+            if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR || inf.datalen < 14)
                 mSampleFormat = SampleType::Int16;
             else
             {
-- 
cgit v1.2.3