Menu

#478 has_md5sum fails when first byte of md5sum is zero.

1.3.x
open
nobody
None
5
2022-03-01
2020-03-05
kda
No

This happens for me on Ubuntu 19.10. Both from repo and built from source.
This does not happen on Raspbian Stretch.

I'm guessing some subtlety about the compiler.
I've attached a patch.
I've attached an offending flac.

The patch inline:

--- flac-1.3.3/src/flac/decode.c        2018-08-25 01:56:06.666934412 -0700
+++ flac-1.3.3.kda/src/flac/decode.c    2020-03-05 09:44:42.825560660 -0800
@@ -1306,8 +1306,9 @@

        if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
                FLAC__uint64 skip, until;

+    FLAC__byte emptyMD5[16] =   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
                decoder_session->got_stream_info = true;
-               decoder_session->has_md5sum = memcmp(metadata->data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
+               decoder_session->has_md5sum = memcmp(metadata->data.stream_info.md5sum, emptyMD5, 16);
                decoder_session->bps = metadata->data.stream_info.bits_per_sample;
                decoder_session->channels = metadata->data.stream_info.channels;
                decoder_session->sample_rate = metadata->data.stream_info.sample_rate;

2 Attachments

Discussion

  • Till Schäfer

    Till Schäfer - 2020-04-27

    I can confirm the bug on gentoo after rebuilding flac 1.3.3. with gcc 9.3.0 (worked with gcc 9.2.0).

     
  • Till Schäfer

    Till Schäfer - 2020-04-27

    downstream bug reference: https://bugs.gentoo.org/719792

     
  • Till Schäfer

    Till Schäfer - 2020-04-27

    my analysis about the gcc versions was wrong, working was gcc 8.3 and failing was gcc 9.{2,3}

     
  • Till Schäfer

    Till Schäfer - 2021-01-20

    an in depth analysis downstream (see gentoo bug https://bugs.gentoo.org/719792) has revealed, that this issue is occurring only with certain optimization levels.

    Furthermore a minimal test example was created for assamber analysis (attached).
    Compiled with gcc -O2 -S -o test.s test.c callback1 (the erroneous case), is reduced to
    movzbl 56(%rsi), %eax
    movl %eax, (%rdx)
    ret

    Calling gcc with -O1 actually calls memcmp.

     
  • Till Schäfer

    Till Schäfer - 2021-01-20

    Given the above analysis a more minmal patch, which produced a better assembly was created. (just adding a != 0 check to convert FLAC__bool to an actual bool (FLAC__bool is int)

     

    Last edit: Till Schäfer 2021-01-20
  • Martijn van Beurden

    I'm sorry this wasn't replied to earlier, but these trackers are pretty much abandoned. A workaround was included in the 1.3.4 release.

    More information can be found here: https://github.com/xiph/flac/pull/227

     

Log in to post a comment.

MongoDB Logo MongoDB