Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height
@ 2023-09-06  0:35 Paul B Mahol
  2023-09-06  6:16 ` Tomas Härdin
  0 siblings, 1 reply; 4+ messages in thread
From: Paul B Mahol @ 2023-09-06  0:35 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 10 bytes --]

Attached.

[-- Attachment #2: 0001-avcodec-yuv4enc-do-not-read-past-end-of-input-in-cas.patch --]
[-- Type: text/x-patch, Size: 1383 bytes --]

From 8295be1415649255b26cfdb0308d7be208711b4d Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Wed, 6 Sep 2023 02:27:56 +0200
Subject: [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd
 height

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/yuv4enc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavcodec/yuv4enc.c b/libavcodec/yuv4enc.c
index 8123260d5d..dd1874ff25 100644
--- a/libavcodec/yuv4enc.c
+++ b/libavcodec/yuv4enc.c
@@ -41,7 +41,7 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     u = pic->data[1];
     v = pic->data[2];
 
-    for (i = 0; i < avctx->height + 1 >> 1; i++) {
+    for (i = 0; i < avctx->height >> 1; i++) {
         for (j = 0; j < avctx->width + 1 >> 1; j++) {
             *dst++ = u[j] ^ 0x80;
             *dst++ = v[j] ^ 0x80;
@@ -55,6 +55,17 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         v +=     pic->linesize[2];
     }
 
+    if (avctx->height & 1) {
+        for (j = 0; j < avctx->width + 1 >> 1; j++) {
+            *dst++ = u[j] ^ 0x80;
+            *dst++ = v[j] ^ 0x80;
+            *dst++ = y[2 * j    ];
+            *dst++ = y[2 * j + 1];
+            *dst++ = y[2 * j    ];
+            *dst++ = y[2 * j + 1];
+        }
+    }
+
     *got_packet = 1;
     return 0;
 }
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height
  2023-09-06  0:35 [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height Paul B Mahol
@ 2023-09-06  6:16 ` Tomas Härdin
  2023-09-06 11:18   ` Anton Khirnov
  0 siblings, 1 reply; 4+ messages in thread
From: Tomas Härdin @ 2023-09-06  6:16 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

ons 2023-09-06 klockan 02:35 +0200 skrev Paul B Mahol:
> +    if (avctx->height & 1) {
> +        for (j = 0; j < avctx->width + 1 >> 1; j++) {

Don't we usually wrap shifted expressions in parentheses? I know >> is
lower presedence than + (a wtf in itself tbh) but I seem to recall
parens being the norm in much of the codebase.

/Tomas
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height
  2023-09-06  6:16 ` Tomas Härdin
@ 2023-09-06 11:18   ` Anton Khirnov
  2023-09-06 11:33     ` Andreas Rheinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Anton Khirnov @ 2023-09-06 11:18 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Tomas Härdin (2023-09-06 08:16:12)
> ons 2023-09-06 klockan 02:35 +0200 skrev Paul B Mahol:
> > +    if (avctx->height & 1) {
> > +        for (j = 0; j < avctx->width + 1 >> 1; j++) {
> 
> Don't we usually wrap shifted expressions in parentheses? I know >> is
> lower presedence than + (a wtf in itself tbh) but I seem to recall
> parens being the norm in much of the codebase.

Using ">> 1" to mean "/ 2" is a relic from the days of non-optimizing
compilers anyway.

-- 
Anton Khirnov
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height
  2023-09-06 11:18   ` Anton Khirnov
@ 2023-09-06 11:33     ` Andreas Rheinhardt
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2023-09-06 11:33 UTC (permalink / raw)
  To: ffmpeg-devel

Anton Khirnov:
> Quoting Tomas Härdin (2023-09-06 08:16:12)
>> ons 2023-09-06 klockan 02:35 +0200 skrev Paul B Mahol:
>>> +    if (avctx->height & 1) {
>>> +        for (j = 0; j < avctx->width + 1 >> 1; j++) {
>>
>> Don't we usually wrap shifted expressions in parentheses? I know >> is
>> lower presedence than + (a wtf in itself tbh) but I seem to recall
>> parens being the norm in much of the codebase.
> 
> Using ">> 1" to mean "/ 2" is a relic from the days of non-optimizing
> compilers anyway.
> 

Incorrect for signed expressions (right shift rounds to -inf, division
to zero).

- Andreas

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-06 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06  0:35 [FFmpeg-devel] [PATCH] avcodec/yuv4enc: do not read past end of input in case of odd height Paul B Mahol
2023-09-06  6:16 ` Tomas Härdin
2023-09-06 11:18   ` Anton Khirnov
2023-09-06 11:33     ` Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git