#365 problem with 'set_metadata' function

libFLAC++ (6)
Jianwen Tan

Here is a part of member function 'bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)':

for(unsigned i = 0; i < num_blocks; i++) {
// we can get away with the const_cast since we know the encoder will only correct the is_last flags
m[i] = const_cast< ::FLAC__StreamMetadata*>((const ::FLAC__StreamMetadata*)metadata[i]);

I think the type-casting to 'const ::FLAC__StreamMetadata*' is intended to invoke operator 'const ::FLAC__StreamMetadata*()' to get the pointer to an object of type '::FLAC__StreamMetadata'. But actually this type-casting is done from a data of type 'Prototype*' which I think is supposed to be 'Prototype'. And this results in an incorrect behavior that only the address is passed to 'm[i]' instead of the pointer to a '::FLAC__StreamMeta' data.


  • hs

    hs - 2010-11-04

    I can confirm this bug. 'metadata[i]' is cast to 'const ::FLAC__StreamMetadata *' using a reinterpret_cast, resulting in corrupt data in m[i]. In order to invoke the 'const ::FLAC__StreamMetadata*() const' operator defined in class Protoype, the code must be changed as follows:
    m[i] = const_cast< ::FLAC__StreamMetadata*>((const ::FLAC__StreamMetadata*)(*metadata[i]));
    Could this be fixed in the repository, please?

  • Erik

    Erik - 2015-03-12
    • status: open --> closed-fixed
    • Group: --> 1.3.0

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks