Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#365 problem with 'set_metadata' function

open
nobody
libFLAC++ (6)
5
2012-12-12
2010-04-02
Jianwen Tan
No

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.

Discussion

  • 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?