Re: [FFmpeg-devel] [PATCH 1/2] avcodec/h264_parser: Fix undefined left shift

2020-05-29 Thread Michael Niedermayer
On Fri, May 29, 2020 at 06:17:54PM +0200, Andreas Rheinhardt wrote:
> Use an uint32_t for the NAL unit size of an AVC H.264 NAL unit instead
> of an int as a left shift of a signed value is undefined behaviour
> if the result doesn't fit into the target type.
> 
> Also make the log message never output negative lengths.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/h264_parser.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)

probably ok

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avcodec/h264_parser: Fix undefined left shift

2020-05-29 Thread Andreas Rheinhardt
Use an uint32_t for the NAL unit size of an AVC H.264 NAL unit instead
of an int as a left shift of a signed value is undefined behaviour
if the result doesn't fit into the target type.

Also make the log message never output negative lengths.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_parser.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index d9249e578d..1d2ce3870c 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -84,12 +84,13 @@ static int h264_find_frame_end(H264ParseContext *p, const 
uint8_t *buf,
 
 for (i = 0; i < buf_size; i++) {
 if (i >= next_avc) {
-int nalsize = 0;
+uint32_t nalsize = 0;
 i = next_avc;
 for (j = 0; j < p->nal_length_size; j++)
 nalsize = (nalsize << 8) | buf[i++];
-if (nalsize <= 0 || nalsize > buf_size - i) {
-av_log(logctx, AV_LOG_ERROR, "AVC-parser: nal size %d 
remaining %d\n", nalsize, buf_size - i);
+if (!nalsize || nalsize > buf_size - i) {
+av_log(logctx, AV_LOG_ERROR, "AVC-parser: nal size %"PRIu32" "
+   "remaining %d\n", nalsize, buf_size - i);
 return buf_size;
 }
 next_avc = i + nalsize;
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".