From fd378b20470d916d839ea2f65faa6036c16e759d Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Fri, 7 Feb 2025 14:50:52 -0500 Subject: [PATCH] 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. --- modules/packetizer/flac.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/packetizer/flac.h b/modules/packetizer/flac.h index 5a15936b2d..7e3664f0f3 100644 --- a/modules/packetizer/flac.h +++ b/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,10 @@ 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; i_header += i_read;