Opened 12 months ago

Last modified 12 months ago

#10363 new defect

Memleak in ogg/opus chained stream metadata

Reported by: toots Owned by:
Priority: important Component: avformat
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by toots)

How to reproduce:

  • Create two short ogg/opus files:
ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a libopus -metadata title="test title" /tmp/test.ogg

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a libopus -metadata title="test title" /tmp/test2.ogg
  • Send a stream to a icecast server

Unfortunately, I couldn't find a way to send a chained ogg bitstream using ffmpeg CLI. It seems to always send a single stream so I used ices (https://icecast.org/ices/)

(Doc on ogg chained bitstreams: https://xiph.org/ogg/doc/oggstream.html)

echo /tmp/test.ogg > /tmp/test.txt
echo /tmp/test2.ogg >> /tmp/test.txt

Ices config:

<?xml version="1.0"?>
<ices>
    <background>0</background>
    <consolelog>1</consolelog>


    <stream>
        <input>
            <module>playlist</module>
            <param name="type">basic</param>
            <param name="file">/tmp/test.m3u</param>
            <param name="once">0</param>
        </input>

        <instance>
            <hostname>localhost</hostname>
            <port>8000</port>
            <password>hackme</password>
            <mount>/test.ogg</mount>
            <yp>0</yp>
        </instance>
    </stream>
</ices>

Finally: ices /tmp/ices.xml

  • Use the attached program to read the stream:
cc opus_memleak.c -g -lavformat -lavutil -o opus_memleak

./opus_memleak http://localhost:8000/test.ogg

Output:

encoder=Lavc60.3.100 libopus;Lavc60.3.100 libopus;Lavc60.3.100 libopus
title=test title
....
encoder=Lavc60.3.100 libopus;Lavc60.3.100 libopus;Lavc60.3.100 libopus
title=test title;test title
...
encoder=Lavc60.3.100 libopus;Lavc60.3.100 libopus;Lavc60.3.100 libopus
title=test title;test title;test title
...
encoder=Lavc60.3.100 libopus;Lavc60.3.100 libopus;Lavc60.3.100 libopus
title=test title;test title;test title;test title
...

Solution: clear stream metadata in libavformat/oggparseopus.c:

    if (priv->need_comments) {
        if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
            return AVERROR_INVALIDDATA;
        av_dict_free(&st->metadata); // HERE
        ff_vorbis_stream_comment(avf, st, packet + 8, os->psize - 8);
        priv->need_comments--;
        return 1;
    }

Patch has been sent but needs an update which will be coming soon.

Attachments (1)

opus_memleak.c (1.4 KB ) - added by toots 12 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 by toots, 12 months ago

Component: undeterminedavformat

comment:2 by toots, 12 months ago

Description: modified (diff)

by toots, 12 months ago

Attachment: opus_memleak.c added

comment:3 by toots, 12 months ago

Description: modified (diff)

comment:4 by toots, 12 months ago

Summary: Memleaak in ogg/opus chained streams metadataMemleak in ogg/opus chained streams metadata

comment:5 by toots, 12 months ago

Priority: normalimportant

comment:6 by toots, 12 months ago

Summary: Memleak in ogg/opus chained streams metadataMemleak in ogg/opus chained stream metadata
Note: See TracTickets for help on using tickets.