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 2977D45945 for ; Tue, 28 Mar 2023 19:37:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 152EA68CC29; Tue, 28 Mar 2023 22:37:01 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E73268C307 for ; Tue, 28 Mar 2023 22:36:54 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 47F14E8A31 for ; Tue, 28 Mar 2023 21:36:37 +0200 (CEST) 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 kWOSJ4MneAz1 for ; Tue, 28 Mar 2023 21:36:35 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id B37C1E8A1D for ; Tue, 28 Mar 2023 21:36:35 +0200 (CEST) Date: Tue, 28 Mar 2023 21:36:35 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20230327164727.13001-1-dheitmueller@ltnglobal.com> Message-ID: References: <20230327164727.13001-1-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v3] decklink: Add support for compressed AC-3 output over SDI 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 Mon, 27 Mar 2023, Devin Heitmueller wrote: > +static int create_s337_payload(AVPacket *pkt, enum AVCodecID codec_id, uint8_t **outbuf, int *outsize) > +{ > + int payload_size = pkt->size + 8; > + uint16_t bitcount = pkt->size * 8; > + uint8_t *s337_payload; > + PutByteContext pb; > + > + if (codec_id != AV_CODEC_ID_AC3) > + return AVERROR(EINVAL); The codec check might be overkill here, after all you are calling this only from code which already checked this. Or later you extend this somehow? > + > + /* Sanity check: According to SMPTE ST 340:2015 Sec 4.1, the AC-3 sync frame will > + exactly match the 1536 samples of baseband (PCM) audio that it represents. */ > + if (pkt->size > 1536) > + return AVERROR(EINVAL); > + > + /* Encapsulate AC3 syncframe into SMPTE 337 packet */ > + s337_payload = (uint8_t *) av_malloc(payload_size); > + if (s337_payload == NULL) > + return AVERROR(ENOMEM); > + bytestream2_init_writer(&pb, s337_payload, payload_size); > + bytestream2_put_le16u(&pb, 0xf872); /* Sync word 1 */ > + bytestream2_put_le16u(&pb, 0x4e1f); /* Sync word 1 */ > + bytestream2_put_le16u(&pb, 0x0001); /* Burst Info, including data type (1=ac3) */ > + bytestream2_put_le16u(&pb, bitcount); /* Length code */ > + for (int i = 0; i < pkt->size; i += 2) > + bytestream2_put_le16u(&pb, (pkt->data[i] << 8) | pkt->data[i+1]); This can overread/ovewrite 1 byte if pkt->size is odd. 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".