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

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Feb 8 22:10:43 UTC 2025



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
fd378b20 by Tristan Matthews at 2025-02-08T21:37:26+00: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.

- - - - -
d0100b92 by Tristan Matthews at 2025-02-08T21:37:26+00: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

- - - - -


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/0ddf69feccd687f0a694aeeefbc31c76074103ec...d0100b92ac9997fece08052b2abb90e4f519ae3a

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0ddf69feccd687f0a694aeeefbc31c76074103ec...d0100b92ac9997fece08052b2abb90e4f519ae3a
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