From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id D4D5945BEC for ; Sat, 25 Mar 2023 17:10:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61FFA68C823; Sat, 25 Mar 2023 19:10:03 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6186C68C659 for ; Sat, 25 Mar 2023 19:09:56 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A5915E8B3E for ; Sat, 25 Mar 2023 18:09:36 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xtcu79DA_z9m for ; Sat, 25 Mar 2023 18:09:34 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 61945E6818 for ; Sat, 25 Mar 2023 18:09:32 +0100 (CET) Date: Sat, 25 Mar 2023 18:09:32 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: Message-ID: References: <20230317150232.17804-1-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec: Fix warnings with signed/unsigned compare in bitstream.h X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Sat, 25 Mar 2023, Andreas Rheinhardt wrote: > Devin Heitmueller: >> When including the header in decklink_enc.cpp it would be fed >> through the C++ compiler rather than the C compiler, which has >> more strict warnings when comparing signed/unsigned values. >> >> Make the local variables unsigned to match the arguments they are >> being passed for those functions. >> >> Signed-off-by: Devin Heitmueller >> --- >> libavcodec/bytestream.h | 10 +++++----- >> 1 file changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h >> index d0033f14f3..67080604b9 100644 >> --- a/libavcodec/bytestream.h >> +++ b/libavcodec/bytestream.h >> @@ -180,7 +180,7 @@ static av_always_inline void bytestream2_skipu(GetByteContext *g, >> static av_always_inline void bytestream2_skip_p(PutByteContext *p, >> unsigned int size) >> { >> - int size2; >> + unsigned int size2; >> if (p->eof) >> return; >> size2 = FFMIN(p->buffer_end - p->buffer, size); >> @@ -268,7 +268,7 @@ static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, >> uint8_t *dst, >> unsigned int size) >> { >> - int size2 = FFMIN(g->buffer_end - g->buffer, size); >> + unsigned int size2 = FFMIN(g->buffer_end - g->buffer, size); >> memcpy(dst, g->buffer, size2); >> g->buffer += size2; >> return size2; >> @@ -287,7 +287,7 @@ static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, >> const uint8_t *src, >> unsigned int size) >> { >> - int size2; >> + unsigned int size2; >> if (p->eof) >> return 0; >> size2 = FFMIN(p->buffer_end - p->buffer, size); >> @@ -311,7 +311,7 @@ static av_always_inline void bytestream2_set_buffer(PutByteContext *p, >> const uint8_t c, >> unsigned int size) >> { >> - int size2; >> + unsigned int size2; >> if (p->eof) >> return; >> size2 = FFMIN(p->buffer_end - p->buffer, size); >> @@ -348,7 +348,7 @@ static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, >> GetByteContext *g, >> unsigned int size) >> { >> - int size2; >> + unsigned int size2; >> >> if (p->eof) >> return 0; > > The bytestream APIs are allowed to overread if the buffer is padded and > the user manages this himself. So you are not allowed to presume that > g->buffer_end - g->buffer is positive. I am not sure if overread/overwrote is a supported state for these functions. As far as I see bytestream2_get_buffer, bytestream2_put_buffer, bytestream2_copy_buffer and bytestream2_set_buffer just crashes if buffer_end < buffer because sooner or later memcpy/memset gets a negative value. There are no special checks to handle it. Regards, Marton _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".