Opened 5 years ago

Last modified 11 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: fireattack 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 (4)

comment:1 by Carl Eugen Hoyos, 5 years ago

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.

comment:2 by fireattack, 22 months ago

Cc: fireattack added
Note: See TracTickets for help on using tickets.