Unknown Address Fault for APIC.toBase64().data()

Michael Pyne mpyne at kde.org
Fri Aug 25 01:51:40 UTC 2017


On Thu, Aug 24, 2017 at 12:46:23PM -0400, Timothy Stoyanovski wrote:
> Hello,
> 
> I'm having an interesting issue with 1 particular mp3. Below is my code:
> 
> TagLib::ID3v2::AttachedPictureFrame * frame =
> (TagLib::ID3v2::AttachedPictureFrame *)(*it);
> 
> if (frame!=nullptr && frame->size() > 0) {
> 
>     auto len = frame->picture().toBase64().size();
> 
>     if (len) { // size: 741376
> 
>         outfile << "generated apic" << '\n';
> 
>         outfile << frame->picture().toBase64() << '\n';  // <—— is okay
> 
>         outfile << frame->picture().toBase64().data() << '\n'; <—— CRASH
> 
> Is there any way to identify why this crashes, and why does .data() cause
> the crash?

I can never get C++ lifetime rules fully memorized, but I think it is
likely that the temporary ByteVector returned by
frame->picture().toBase64() is deleted automatically in between the
.data() call and the output to outfile.  That is, the compiler
rearranges that crashing line to something like:

{
  // ...
  const char * dataPtr;
  {
    const ByteVector vector = frame->picture().toBase64();
    dataPtr = vector.data();
  }
  // vector destructed here, dataPtr not safe to use
  outfile.operator<<(dataPtr); // crash
}

If you do something like

        const auto &temp = frame->picture().toBase64();
        outfile << temp.data() << '\n';

and that works, then it's probably this issue.

Regards,
 - Michael Pyne


More information about the taglib-devel mailing list