From 072e6a6405938cde83d6d0cc7fdcd95ad8d4ee61 Mon Sep 17 00:00:00 2001 From: Till Mayer Date: Thu, 18 Jun 2020 20:00:32 +0200 Subject: [PATCH] WavLoader: Search for DATA marker by reading single bytes Previously 4 bytes at once were read and compared to the string "DATA". This worked when the DATA marker was aligned on a 32-bit boundary relative to the start of the file. However, this is not guranteed to always be the case, and for some files the loader would just keep searching for the marker. --- Libraries/LibAudio/WavLoader.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Libraries/LibAudio/WavLoader.cpp b/Libraries/LibAudio/WavLoader.cpp index d42ee49f5a..2248a1d9fe 100644 --- a/Libraries/LibAudio/WavLoader.cpp +++ b/Libraries/LibAudio/WavLoader.cpp @@ -155,16 +155,27 @@ bool WavLoader::parse_header() // Read chunks until we find DATA bool found_data = false; u32 data_sz = 0; + u8 search_byte = 0; while (true) { - u32 chunk_id; - stream >> chunk_id; - CHECK_OK("Reading chunk ID searching for data"); + stream >> search_byte; + CHECK_OK("Reading byte searching for data"); + if (search_byte != 0x64) //D + continue; + + stream >> search_byte; + CHECK_OK("Reading next byte searching for data"); + if (search_byte != 0x61) //A + continue; + + u16 search_remaining = 0; + stream >> search_remaining; + CHECK_OK("Reading remaining bytes searching for data"); + if (search_remaining != 0x6174) //TA + continue; + stream >> data_sz; - CHECK_OK("Reading chunk size searching for data"); - if (chunk_id == 0x61746164) { // DATA - found_data = true; - break; - } + found_data = true; + break; } ok = ok && found_data;