[vlc-commits] [Git][videolan/vlc][master] 2 commits: mux: mpeg: fix overflow handling

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Fri Sep 13 05:25:14 UTC 2024



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
dba9bb94 by Alaric Senat at 2024-09-13T05:08:27+00:00
mux: mpeg: fix overflow handling

Fixes regressions from 3856f9fce93471c1d36bc6fdc34ad92484d79be2.

The previous barrier was using `i_count` as a **byte** count instead of
a **bit** count leading to the function bailing for legitimate writes.
This patches takes into account the remaining bits to write under the
buffer cursor in its overflow check.

- - - - -
4746ea56 by Alaric Senat at 2024-09-13T05:08:27+00:00
mux: mpeg: check overflow in bit alignment

Avoid an overflow when `bits_align` is called at the end of the
available size.

- - - - -


1 changed file:

- modules/mux/mpeg/bits.h


Changes:

=====================================
modules/mux/mpeg/bits.h
=====================================
@@ -21,6 +21,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include <limits.h>
+#include <stdbit.h>
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -55,15 +57,22 @@ static inline void bits_align( bits_buffer_t *p_buffer )
     if( p_buffer->i_mask != 0x80 && p_buffer->i_data < p_buffer->i_size )
     {
         p_buffer->i_mask = 0x80;
-        p_buffer->i_data++;
-        p_buffer->p_data[p_buffer->i_data] = 0x00;
+        if( ++p_buffer->i_data < p_buffer->i_size )
+            p_buffer->p_data[p_buffer->i_data] = 0x00;
     }
 }
 
+static inline bool bits_will_overflow( const bits_buffer_t *buff, int count )
+{
+    const int leftover = count - (stdc_trailing_zeros(buff->i_mask) + 1);
+    const int byte_shift = (leftover + CHAR_BIT - 1) / CHAR_BIT;
+    return buff->i_data + byte_shift >= buff->i_size;
+}
+
 static inline void bits_write( bits_buffer_t *p_buffer,
                                int i_count, uint64_t i_bits )
 {
-    if (p_buffer->i_data + i_count < p_buffer->i_size)
+    if( bits_will_overflow(p_buffer, i_count) )
         return;
 
     while( i_count > 0 )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b132d09580a85907e52a52624bd8d2a90da9629d...4746ea56dcf4e6a38dffdfdcade192fa6a21d8c7

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b132d09580a85907e52a52624bd8d2a90da9629d...4746ea56dcf4e6a38dffdfdcade192fa6a21d8c7
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list