Opened 3 months ago

Last modified 3 months ago

#7641 new defect

MOV demuxer hogs lots of memory for encrypted files

Reported by: Starchild Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mov
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
Due to unfrotunate memory management in the mov demuxer, systems with low hardware specs run out of memory while playing encrypted MP4 streams.
This is due to the mov_try_read_block allocating 1 MB blocks regardless of the size that was actually required. They are not shrunk to their actual size and only freed when the context gets closed.
Specifically, it happens while processing saiz atoms (auxiliary_info_sizes buffer).

How to reproduce: Process a CENC-encrypted stream with a runtime of 1 hour that has around a thousand moof fragments inside the MP4 on a low-spec box (say, 150 MB of available memory).

Possible fix (works for me):
Change tail of mov_try_read_block to do shrinking. Alternatively don't allocate a huge buffer in the first place when a smaller size is known?

    *data = av_realloc(buffer, size);
    if (!*data) {
        av_free(buffer);
        return AVERROR(ENOMEM);
    }

Change History (1)

comment:1 Changed 3 months ago by cehoyos

Please either provide the command line you tested together with the complete, uncut console output and a sample to make this a valid ticket or - even better - send your patch - made with git format-patch - to the development mailing list.

Note: See TracTickets for help on using tickets.