Browse Source

LibAudio/aplay: Handle WAV header errors properly

We shouldn't just ASSERT() if the header parse fails. This was crashing
Piano completely.
William McPherson 5 năm trước cách đây
mục cha
commit
d55d2b2794
2 tập tin đã thay đổi với 7 bổ sung2 xóa
  1. 3 2
      Libraries/LibAudio/WavLoader.cpp
  2. 4 0
      Userland/aplay.cpp

+ 3 - 2
Libraries/LibAudio/WavLoader.cpp

@@ -40,7 +40,9 @@ WavLoader::WavLoader(const StringView& path)
         return;
     }
 
-    parse_header();
+    if (!parse_header())
+        return;
+
     m_resampler = make<ResampleHelper>(m_sample_rate, 44100);
 }
 
@@ -81,7 +83,6 @@ bool WavLoader::parse_header()
 
 #define CHECK_OK(msg)                                                           \
     do {                                                                        \
-        ASSERT(ok);                                                             \
         if (stream.handle_read_failure()) {                                     \
             m_error_string = String::format("Premature stream EOF at %s", msg); \
             return {};                                                          \

+ 4 - 0
Userland/aplay.cpp

@@ -41,6 +41,10 @@ int main(int argc, char** argv)
     auto audio_client = Audio::ClientConnection::construct();
     audio_client->handshake();
     Audio::WavLoader loader(argv[1]);
+    if (loader.has_error()) {
+        fprintf(stderr, "Failed to load WAV file: %s\n", loader.error_string());
+        return 1;
+    }
 
     printf("\033[34;1m Playing\033[0m: %s\n", argv[1]);
     printf("\033[34;1m  Format\033[0m: %u Hz, %u-bit, %s\n",