summaryrefslogtreecommitdiff
path: root/libavutil/mem.c
Commit message (Collapse)AuthorAge
* avutil/mem: Use max_alloc_size as-isAndreas Rheinhardt2020-05-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The size of a single allocation performed by av_malloc() or av_realloc() is supposed to be bounded by max_alloc_size, which defaults to INT_MAX and can be set by the user; yet currently this is not completely honoured: The actual value used is max_alloc_size - 32. How this came to be can only be understood historically: a) 0ecca7a49f8e254c12a3a1de048d738bfbb614c6 disallowed allocations > INT_MAX. At that time the size parameter of av_malloc() was an unsigned and the commentary added ("lets disallow possible ambiguous cases") indicates that this was done as a precaution against calling the functions with negative int values. Genuinely limiting the size of allocations to INT_MAX doesn't seem to have been the intention given that at this time the memalign hack introduced in commit da9b170c6f06184a5114dc66afb8385cd0ffff83 (which when enabled increased the size of allocations slightly so that one can return a correctly aligned pointer that actually does not point to the beginning of the allocated buffer) was already present. b) Said memalign hack allocated 17 bytes more than actually desired, yet allocating 16 bytes more is actually enough and so this was changed in a9493601638b048c44751956d2360f215918800c; this commit also replaced INT_MAX by INT_MAX - 16 (and made the limit therefore a limit on the size of the allocated buffer), but kept the comment, although there is nothing ambiguous about allocating (INT_MAX - 16)..INT_MAX. c) 13dfce3d44f99a2d7df71aba8ae003d58db726f7 then increased 16 to 32 for AVX, 6b4c0be5586acad3bbafd7d2dd02a8328a5ab632 replaced INT_MAX by MAX_MALLOC_SIZE (which was of course defined to be INT_MAX) and 5a8e994287d8ef181c0a5eac537547d7059b4524 added max_alloc_size and made it user-selectable. d) 4fb311c804098d78e5ce5f527f9a9c37536d3a08 then dropped the memalign hack, yet it kept the -32 (probably because the comment about ambiguous cases was still present?), although it is no longer needed at all after this commit. Therefore this commit removes it and uses max_alloc_size directly. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavu/mem: Make other alloc functions more similar to av_malloc().Carl Eugen Hoyos2020-04-12
| | | | | | | Do not limit the array allocation functions and av_calloc() to allocations of INT_MAX, instead depend on max_alloc_size like av_malloc(). Allows a workaround for ticket #7140.
* avutil/mem: Optimize fill32() by unrolling and using 64bitMichael Niedermayer2019-01-20
| | | | | Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc().Carl Eugen Hoyos2018-01-04
|
* lavu/mem: Do not realloc in av_fast_realloc() if size == min_size.Carl Eugen Hoyos2018-01-01
| | | | This can avoid OOM for min_size close to FFmpeg's arbitrary alloc limits.
* avutil: add alignment needed for AVX-512James Darnley2017-12-24
|
* Merge commit '04b0f0e371ff81b682274b574fb465ba4395c09f'James Almer2017-10-30
|\ | | | | | | | | | | | | * commit '04b0f0e371ff81b682274b574fb465ba4395c09f': mem: uninline av_malloc(z)_array() Merged-by: James Almer <jamrial@gmail.com>
| * mem: uninline av_malloc(z)_array()Anton Khirnov2017-04-26
| | | | | | | | | | | | Inlining public functions hardcodes their implementation into the ABI, so it should be avoided unless there is a very good reason for it. No such reason exists in this case.
* | Merge commit '4fb311c804098d78e5ce5f527f9a9c37536d3a08'Clément Bœsch2017-03-20
|\| | | | | | | | | | | | | | | | | | | * commit '4fb311c804098d78e5ce5f527f9a9c37536d3a08': Drop memalign hack Merged, as this may indeed be uneeded since 46e3936fb04d06550151e667357065e3f646da1a. Merged-by: Clément Bœsch <u@pkh.me>
| * Drop memalign hackDiego Biurrun2016-09-03
| | | | | | | | It no longer serves a useful purpose.
* | dynarray: Change AV_ to FF_ for AV_DYNARRAY_ADDTimothy Gu2016-07-31
| | | | | | | | | | The header is not installed and the macro isn't used outside libavutil, so it is obviously privat to libavutil. Make the name reflect that.
* | avutil/mem: fix memleakZhao Zhili2016-07-28
| | | | | | | | | | | | | | The original code assumes av_realloc() will free ptr if size is zero. The assumes is incorrect now. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/mem: Add av_fast_mallocz()Michael Niedermayer2015-11-18
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | Factor duplicated ff_fast_malloc() out into mem_internal.hMichael Niedermayer2015-07-13
| | | | | | | | | | | | | | | | internal.h is difficult to use due to circular dependancies mem.h is a public header ff_* is not public Alternative solutions probably are possible too Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avutil/mem: Fix potential overflow in overallocation codeMichael Niedermayer2015-07-11
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | libavutil/mem: use size_t for the length in av_strdup()Michael Niedermayer2015-05-10
| | | | | | | | | | | | the string length is not constrained to INT_MAX Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/mem: replace remaining void **/*** casts by memcpy()Michael Niedermayer2015-02-03
| | | | | | | | | | | | This is similar to 60392480181f24ebf3ab48d8ac3614705de90152 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit '60392480181f24ebf3ab48d8ac3614705de90152'Michael Niedermayer2015-02-01
|\| | | | | | | | | | | | | | | | | | | * commit '60392480181f24ebf3ab48d8ac3614705de90152': mem: fix pointer pointer aliasing violations Conflicts: libavutil/mem.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: fix pointer pointer aliasing violationsRémi Denis-Courmont2015-02-01
| | | | | | | | | | | | | | | | | | This uses explicit memory copying to read and write pointer to pointers of arbitrary object types. This works provided that the architecture uses the same representation for all pointer types (the previous code made that assumption already anyway). Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
* | Merge commit '8ddc32629a6d6be77256694c9e322dde134609f3'Michael Niedermayer2014-08-14
|\| | | | | | | | | | | | | | | | | | | | | | | * commit '8ddc32629a6d6be77256694c9e322dde134609f3': mem: add av_strndup() for duplicating substrings Conflicts: libavutil/mem.c libavutil/mem.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: add av_strndup() for duplicating substringsAnton Khirnov2014-08-13
| |
* | lavu/mem: add av_dynarray_add_nofree functionLukasz Marek2014-03-29
| | | | | | | | | | | | | | | | av_dynarray_add_nofree function have similar functionality as existing av_dynarray_add, but it doesn't deallocate memory on fails. Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
* | avutil/mem: avoid using intptr_t to access void* in av_dynarray_add()Michael Niedermayer2014-03-22
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | lavu/mem: reimplement the dynarray functions with the macro.Nicolas George2014-03-22
| | | | | | | | | | Signed-off-by: Nicolas George <george@nsup.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4'Michael Niedermayer2013-11-14
|\| | | | | | | | | | | | | | | | | | | | | | | | | * commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4': Move av_fast_{m,re}alloc from lavc to lavu. Conflicts: libavcodec/avcodec.h libavcodec/utils.c libavutil/mem.c libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Move av_fast_{m,re}alloc from lavc to lavu.Anton Khirnov2013-11-14
| |
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2013-10-17
|\| | | | | | | | | | | | | * qatar/master: mem: Make av_strdup allocate using av_realloc Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Make av_strdup allocate using av_reallocMartin Storsjö2013-10-16
| | | | | | | | | | | | | | | | | | This makes sure that pointers from av_strdup are reallocable, which is used in av_dict_set if the AV_DICT_APPEND flag is set. Nothing should rely on pointers from av_strdup being aligned. Signed-off-by: Martin Storsjö <martin@martin.st>
* | Merge commit '67e285ceca1cb602a5ab87010b30d904527924fe'Michael Niedermayer2013-09-21
|\| | | | | | | | | | | | | * commit '67e285ceca1cb602a5ab87010b30d904527924fe': mem: Handle av_reallocp(..., 0) properly Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Handle av_reallocp(..., 0) properlyMartin Storsjö2013-09-20
| | | | | | | | | | | | | | Previously this did a double free (and returned an error). Reported-by: Justin Ruggles Signed-off-by: Martin Storsjö <martin@martin.st>
* | Merge commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7'Michael Niedermayer2013-09-17
|\| | | | | | | | | | | | | | | | | | | | | | | | | * commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7': mem: Introduce av_reallocp Conflicts: doc/APIchanges libavutil/mem.c libavutil/mem.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Introduce av_reallocpLuca Barbato2013-09-16
| |
* | Merge commit 'c3e6e8f06c42499bd020fd0b37f9542150e6067b'Michael Niedermayer2013-09-06
|\| | | | | | | | | | | | | | | | | | | * commit 'c3e6e8f06c42499bd020fd0b37f9542150e6067b': mem: Do not check unsigned values for negative size Conflicts: libavutil/mem.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Do not check unsigned values for negative sizeDiego Biurrun2013-09-05
| |
* | Merge commit 'b634b36fcebfe16b837b6c4044f5d5cb99a75040'Michael Niedermayer2013-09-06
|\| | | | | | | | | | | | | | | | | | | | | * commit 'b634b36fcebfe16b837b6c4044f5d5cb99a75040': mem: Improve documentation wording and spelling Conflicts: libavutil/mem.c libavutil/mem.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Improve documentation wording and spellingDiego Biurrun2013-09-05
| |
* | avutil/mem: Fix flipped conditionMichael Niedermayer2013-08-09
| | | | | | | | | | | | | | Fixes return code and later null pointer dereference Found-by: Laurent Butti <laurentb@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/mem: simplify av_reallocp_array() by using av_realloc_f()Michael Niedermayer2013-06-05
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e'Michael Niedermayer2013-06-05
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e': movenc: Keep track of the allocated size for the cluster array mem: Add av_realloc_array and av_reallocp_array Conflicts: doc/APIchanges libavformat/movenc.c libavutil/mem.c libavutil/mem.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mem: Add av_realloc_array and av_reallocp_arrayMartin Storsjö2013-06-04
| | | | | | | | | | | | These help avoiding overflows and simplify error handling. Signed-off-by: Martin Storsjö <martin@martin.st>
* | lavu/mem: add av_dynarray2_add()Stefano Sabatini2013-05-13
| | | | | | | | | | | | | | | | | | Based on a patch by Clément Bœsch. See thread: From: Clément Bœsch <ubitux@gmail.com> Subject: [FFmpeg-devel] [PATCH 1/5] lavu: add av_dynarray_alloc_elem(). Date: Sun, 14 Apr 2013 03:07:54 +0200
* | lavu: define FF_MEMORY_POISON and use itStefano Sabatini2013-05-13
| | | | | | | | Allow single-place definition of constant used to fill poisoned memory.
* | lavu/mem: fix potential int overflow and crash in av_dynarray_add()Stefano Sabatini2013-05-08
| | | | | | | | Also extend documentation accordingly.
* | avutil/mem: add av_memdup()Michael Niedermayer2013-05-02
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | lavu/mem: remove redundant comment from av_dynarray_add()Stefano Sabatini2013-04-27
| | | | | | | | The function is documented in mem.h.
* | mem: Fix usage of memalign() on DJGPP.Fabrizio Gennari2013-03-10
| | | | | | | | | | Credits to Khusraw of bttr-software.de forum. Signed-off-by: Carl Eugen Hoyos <cehoyos@ag.or.at>
* | Merge commit 'f935aca44c674d30e3ed940ef73bbad1228a5855'Michael Niedermayer2013-02-24
|\| | | | | | | | | | | | | | | | | | | | | | | * commit 'f935aca44c674d30e3ed940ef73bbad1228a5855': av_memcpy_backptr: avoid an infinite loop for back = 0 4xm: check the return value of read_huffman_tables(). Conflicts: libavcodec/4xm.c libavutil/mem.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * av_memcpy_backptr: avoid an infinite loop for back = 0Anton Khirnov2013-02-23
| | | | | | | | CC:libav-stable@libav.org
* | avutil/mem: do a small set of checks for memalign hack before freeing.Michael Niedermayer2013-02-22
| | | | | | | | | | | | These can detect some kinds of memory and or pointer corruptions Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | mem: minor simplification of the alignment hack codeMichael Niedermayer2012-12-14
| | | | | | | | | | Idea-by: wanzhang Signed-off-by: Michael Niedermayer <michaelni@gmx.at>