[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: packetizer: flac: convert read_utf8 to unsigned

Tristan Matthews (@tmatth) gitlab at videolan.org
Tue Feb 11 16:26:03 UTC 2025



Tristan Matthews pushed to branch 3.0.x at VideoLAN / VLC


Commits:
83da242d by Tristan Matthews at 2025-02-10T10:47:21-05:00
packetizer: flac: convert read_utf8 to unsigned

Rationale: this is what the standard implementation (libFLAC) is doing and
there is no need to consider negative samples/frame numbers.

(cherry picked from commit fd378b20470d916d839ea2f65faa6036c16e759d)

- - - - -
8678d1e3 by Tristan Matthews at 2025-02-10T10:47:53-05:00
packetizer: flac: avoid integer overflow

Fixes #29010
Fixes https://issues.oss-fuzz.com/issues/42503720

found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/vlc
(cherry picked from commit d0100b92ac9997fece08052b2abb90e4f519ae3a)

- - - - -


1 changed file:

- modules/packetizer/flac.h


Changes:

=====================================
modules/packetizer/flac.h
=====================================
@@ -64,16 +64,16 @@ static inline void FLAC_ParseStreamInfo( const uint8_t *p_buf,
     stream_info->total_samples = GetQWBE(&p_buf[4+6]) & ((INT64_C(1)<<36)-1);
 }
 
-/* Will return INT64_MAX for an invalid utf-8 sequence */
-static inline int64_t read_utf8(const uint8_t *p_buf, unsigned i_buf, int *pi_read)
+/* Will return UINT64_MAX for an invalid utf-8 sequence */
+static inline uint64_t read_utf8(const uint8_t *p_buf, unsigned i_buf, int *pi_read)
 {
     /* Max coding bits is 56 - 8 */
     /* Value max precision is 36 bits */
-    int64_t i_result = 0;
+    uint64_t i_result = 0;
     unsigned i;
 
     if(i_buf < 1)
-        return INT64_MAX;
+        return UINT64_MAX;
 
     if (!(p_buf[0] & 0x80)) { /* 0xxxxxxx */
         i_result = p_buf[0];
@@ -97,15 +97,15 @@ static inline int64_t read_utf8(const uint8_t *p_buf, unsigned i_buf, int *pi_re
         i_result = 0;
         i = 6;
     } else {
-        return INT64_MAX;
+        return UINT64_MAX;
     }
 
     if(i_buf < i + 1)
-        return INT64_MAX;
+        return UINT64_MAX;
 
     for (unsigned j = 1; j <= i; j++) {
         if (!(p_buf[j] & 0x80) || (p_buf[j] & 0x40)) { /* 10xxxxxx */
-            return INT64_MAX;
+            return UINT64_MAX;
         }
         i_result <<= 6;
         i_result |= (p_buf[j] & 0x3F);
@@ -239,8 +239,14 @@ static inline int FLAC_ParseSyncInfo(const uint8_t *p_buf, unsigned i_buf,
 
     /* Check Sample/Frame number */
     int i_read;
-    int64_t i_fsnumber = read_utf8(&p_buf[i_header++], i_buf - 4, &i_read);
-    if ( i_fsnumber == INT64_MAX )
+    uint64_t i_fsnumber = read_utf8(&p_buf[i_header++], i_buf - 4, &i_read);
+
+    /* Invalid UTF-8 */
+    if (i_fsnumber == UINT64_MAX)
+        return 0;
+
+    /* Invalid Sample/Frame number */
+    if (stream_info->total_samples != 0 && i_fsnumber > stream_info->total_samples)
         return 0;
 
     i_header += i_read;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3e64644242783c68892262b11c178a1c668ab14a...8678d1e317a9e57e1f52a74229106a93573a4e90

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3e64644242783c68892262b11c178a1c668ab14a...8678d1e317a9e57e1f52a74229106a93573a4e90
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