simplemad icon indicating copy to clipboard operation
simplemad copied to clipboard

simplemad::Decoder<R>::decode returns Err(EOF)

Open ahwatts opened this issue 3 years ago • 1 comments

I spent an eternity tracking this down, but on pc-windows-msvc, with simplemad 0.9.0, simplemad_sys 0.5.0, and rustc 1.67.0-nightly (c1a859b25 2022-11-10), creating a Decoder instance on a file that exists, has data, and a valid reader returns Err(EOF). I have a minimal example here:

https://github.com/ahwatts/simplemad-test

Running it against stable:

C:\Users\Andrew\Projects\simplemad-test〉rustc --version                                                                                                                                                                                                11/25/2022 01:35:45 PMrustc 1.65.0 (897e37553 2022-11-02)
C:\Users\Andrew\Projects\simplemad-test〉cargo build                                                                                                                                                                                                    11/25/2022 01:35:52 PM   Compiling gcc v0.3.55
   Compiling pkg-config v0.3.26
   Compiling libc v0.1.12
   Compiling simplemad_sys v0.5.0
   Compiling simplemad v0.9.0
   Compiling simplemad-test v0.1.0 (C:\Users\Andrew\Projects\simplemad-test)
    Finished dev [unoptimized + debuginfo] target(s) in 2.45s
C:\Users\Andrew\Projects\simplemad-test〉.\target\debug\simplemad-test.exe                                                                                                                                                                              11/25/2022 01:35:58 PM
Decoder is ok

And the output of running it with nightly:

C:\Users\Andrew\Projects\simplemad-test〉rustc +nightly --version                                                                                                                                                                                       11/25/2022 01:34:26 PMrustc 1.67.0-nightly (c1a859b25 2022-11-10)
C:\Users\Andrew\Projects\simplemad-test〉cargo +nightly build                                                                                                                                                                                           11/25/2022 01:34:38 PM   Compiling pkg-config v0.3.26
   Compiling gcc v0.3.55
   Compiling libc v0.1.12
   Compiling simplemad_sys v0.5.0
   Compiling simplemad v0.9.0
   Compiling simplemad-test v0.1.0 (C:\Users\Andrew\Projects\simplemad-test)
    Finished dev [unoptimized + debuginfo] target(s) in 2.45s
C:\Users\Andrew\Projects\simplemad-test〉.\target\debug\simplemad-test.exe                                                                                                                                                                              11/25/2022 01:34:46 PM
Decoder is not ok: Some(EOF)

It looks like the issue is here:

https://github.com/RustAudio/simplemad/blob/master/simplemad_sys/libmad-src/frame.c#L70

The variable header->layer is being initialized to 0, but 0 is not a valid enum value for enum mad_layer, which can only have 1, 2, or 3. I'm not sure why this causes Rust to freak out (but only on nightly), but changing that line in frame.c to:

  header->layer          = MAD_LAYER_I;

fixes it when running against nightly.

ahwatts avatar Nov 25 '22 18:11 ahwatts

On aarch64, the same issue causes an I/O error that then causes a segfault if you try to run std::fmt::Display::fmt on it:

* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3b9aca00)
    frame #0: 0x000000010029152c organic-snout`_$LT$std..io..error..Error$u20$as$u20$core..fmt..Display$GT$::fmt::hed2bb451a324f5d8 at error.rs:944:46 [opt]

ahwatts avatar May 20 '23 22:05 ahwatts