Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
279758e3 by Romain Vimont at 2023-02-11T07:31:00+00:00
randomizer: do not pass NULL to memcpy()

When switching playback order from NORMAL to RANDOM, the current
playlist items are added to the randomizer.

However, if the playlist is empty, the items vector is empty, and its
.data field is NULL. This causes the following error in ASAN:

    ../../src/playlist/randomizer.c:426:10: runtime error: null pointer
    passed as argument 2, which is declared to never be null

If the playlist size is 0, then do not call randomizer_Add() at all.

- - - - -
5ebf9e28 by Romain Vimont at 2023-02-11T07:31:00+00:00
vlc_vector: assert count argument is not 0

Several vlc_vector functions must not be called with count == 0:
 - it's useless (e.g. pushing 0 items to a vector)
 - with the current implementation, it can cause memcpy() to be called
   to copy 0 bytes (useless) with NULL pointer for the src parameter
   (triggers an error in ASAN).

- - - - -


2 changed files:

- include/vlc_vector.h
- src/playlist/control.c


Changes:

=====================================
include/vlc_vector.h
=====================================
@@ -20,6 +20,7 @@
 #ifndef VLC_VECTOR_H
 #define VLC_VECTOR_H
 
+#include <assert.h>
 #include <stdbool.h>
 #include <stddef.h>
 
@@ -332,6 +333,7 @@ vlc_vector_growsize_(size_t value)
 
 #define vlc_vector_push_all_internal_(pv, items, count) \
 ( \
+    assert(count), \
     vlc_vector_check_same_ptr_type_((pv)->data, items), \
     vlc_vector_reserve(pv, (pv)->size + (count)) && \
     ( \
@@ -359,6 +361,7 @@ vlc_vector_growsize_(size_t value)
 
 #define vlc_vector_insert_hole_internal_(pv, index, count) \
 ( \
+    assert(count), \
     vlc_vector_reserve(pv, (pv)->size + (count)) && \
     ( \
         (index) == (pv)->size || \
@@ -467,6 +470,7 @@ vlc_vector_rotate_array_right_(char *array, size_t len, 
size_t distance)
 static inline void
 vlc_vector_move_(char *array, size_t index, size_t count, size_t target)
 {
+    assert(count);
     if (index < target)
         vlc_vector_rotate_array_left_(&array[index], target - index + count,
                                       count);
@@ -529,6 +533,7 @@ vlc_vector_move_(char *array, size_t index, size_t count, 
size_t target)
 
 #define vlc_vector_remove_slice_noshrink_internal_(pv, index, count) \
     do { \
+        assert(count); \
         if ((index) + (count) < (pv)->size) \
             memmove(&(pv)->data[index], \
                     &(pv)->data[(index) + (count)], \


=====================================
src/playlist/control.c
=====================================
@@ -36,8 +36,9 @@ vlc_playlist_PlaybackOrderChanged(vlc_playlist_t *playlist)
     {
         /* randomizer is expected to be empty at this point */
         assert(randomizer_Count(&playlist->randomizer) == 0);
-        randomizer_Add(&playlist->randomizer, playlist->items.data,
-                       playlist->items.size);
+        if (playlist->items.size)
+            randomizer_Add(&playlist->randomizer, playlist->items.data,
+                           playlist->items.size);
 
         bool loop = playlist->repeat == VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
         randomizer_SetLoop(&playlist->randomizer, loop);



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/46e9fb3737c1576a1897c83eb2855199cdb32226...5ebf9e280118b90ad41698c208f60c58b2b3e8ca

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/46e9fb3737c1576a1897c83eb2855199cdb32226...5ebf9e280118b90ad41698c208f60c58b2b3e8ca
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to