From 0b03ad4c097627fef5b21df5329b98c5f223436c Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 11 Nov 2018 18:55:34 +0000 Subject: [PATCH] Fix a potential crashes in BWF (WAV) file writes --- Audio/BWFFile.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Audio/BWFFile.cpp b/Audio/BWFFile.cpp index 364fa8f24..e293cbb3f 100644 --- a/Audio/BWFFile.cpp +++ b/Audio/BWFFile.cpp @@ -36,7 +36,8 @@ namespace { if (id) { - auto len = std::min (size_t (4), strlen (id)); + auto end = reinterpret_cast (::memchr (id, '\0', 4u)); + auto len = end ? end - id : 4u; memcpy (id_.data (), id, len); if (len < 4u) { @@ -45,7 +46,7 @@ namespace } else { - memcpy (id_.data (), "JUNK", 4); + memcpy (id_.data (), "JUNK", 4u); } } @@ -831,7 +832,8 @@ void BWFFile::bext_coding_history (QByteArray const& text) m_->header_dirty_ = true; m_->bext (); // ensure we have a correctly // initialized m_->bext_ - auto length = std::min (strlen (text.constData ()), size_t (text.size ())); + auto end = static_cast (::memchr (text.constData (), '\0', size_t (text.size ()))); + auto length = end ? end - text.constData () : size_t (text.size ()); m_->bext_.resize (sizeof (BroadcastAudioExtension) + length); std::strncpy (m_->bext ()->coding_history_, text.constData (), length); }