History

avfilter/vf_unsharp: Don't dereference NULL

The unsharp filter uses an array of arrays of uint32_t, each of which is separately allocated. These arrays also need to freed separately; but before doing so, one needs to check whether the array of arrays has actually been allocated, otherwise one would dereference a NULL pointer. This fixes #8408. Furthermore, the array of arrays needs to be zero-initialized so that no uninitialized pointer will be freed in case an allocation of one of the individual arrays fails.

Andreas Rheinhardt committed 6 years ago

Commit 710ab131 parent 968c4cb1 file · +6 −4Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_unsharp.c+6−4
@@ -218,7 +218,7 @@ static int init_filter_param(AVFilterContext *ctx, UnsharpFilterParam *fp, const · 217 unmodified lines
218218 effect, effect_type, fp->msize_x, fp->msize_y, fp->amount / 65535.0);
219219
220220 fp->sr = av_malloc_array((MAX_MATRIX_SIZE - 1) * s->nb_threads, sizeof(uint32_t));
221− fp->sc = av_malloc_array(2 * fp->steps_y * s->nb_threads, sizeof(uint32_t **));
221+ fp->sc = av_mallocz_array(2 * fp->steps_y * s->nb_threads, sizeof(uint32_t *));
222222 if (!fp->sr || !fp->sc)
223223 return AVERROR(ENOMEM);
224224
@@ -258,9 +258,11 @@ static void free_filter_param(UnsharpFilterParam *fp, int nb_threads) · 33 unmodified lines
258258 {
259259 int z;
260260
261− for (z = 0; z < 2 * fp->steps_y * nb_threads; z++)
262− av_freep(&fp->sc[z]);
263− av_freep(&fp->sc);
261+ if (fp->sc) {
262+ for (z = 0; z < 2 * fp->steps_y * nb_threads; z++)
263+ av_freep(&fp->sc[z]);
264+ av_freep(&fp->sc);
265+ }
264266 av_freep(&fp->sr);
265267 }
266268

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t