From: javashu2012@gmail.com To: ffmpeg-devel@ffmpeg.org Cc: bevis <javashu2012@gmail.com> Subject: [FFmpeg-devel] [PATCH v1] avcodec/sbc_parser: Fix parser error when reading data slowly. Date: Thu, 20 Oct 2022 11:43:25 +0800 Message-ID: <20221020034325.77436-1-javashu2012@gmail.com> (raw) From: bevis <javashu2012@gmail.com> When reading data is slow, such as 10 bytes at a time, the header bytes will be overwritten by the body data, resulting in an error in parsing the header. Signed-off-by: bevis <javashu2012@gmail.com> --- libavcodec/sbc_parser.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c index 2d427cc7cb..bf471cf878 100644 --- a/libavcodec/sbc_parser.c +++ b/libavcodec/sbc_parser.c @@ -81,26 +81,40 @@ static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx, { SBCParseContext *pc = s->priv_data; int next; + int expected_header_size = sizeof(pc->header); if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { next = buf_size; } else { - if (pc->header_size) { - memcpy(pc->header + pc->header_size, buf, - sizeof(pc->header) - pc->header_size); - next = sbc_parse_header(s, avctx, pc->header, sizeof(pc->header)) - - pc->buffered_size; - pc->header_size = 0; - } else { + if (!pc->header_size) { next = sbc_parse_header(s, avctx, buf, buf_size); if (next >= buf_size) next = -1; + } else if (pc->header_size + buf_size >= expected_header_size) { + if (pc->header_size < expected_header_size) { + memcpy(pc->header + pc->header_size, buf, + expected_header_size - pc->header_size); + pc->header_size = expected_header_size; + } + next = sbc_parse_header(s, avctx, pc->header, expected_header_size) + - pc->buffered_size; + if (next >= buf_size) { + next = -1; + } else { + pc->header_size = 0; + pc->buffered_size = 0; + } + } else { + next = -1; } if (next < 0) { - pc->header_size = FFMIN(sizeof(pc->header), buf_size); - memcpy(pc->header, buf, pc->header_size); - pc->buffered_size = buf_size; + if (pc->header_size < expected_header_size) { + memcpy(pc->header + pc->header_size, buf, + FFMIN(buf_size, expected_header_size - pc->header_size)); + pc->header_size = FFMIN(expected_header_size, pc->header_size + buf_size); + } + pc->buffered_size += buf_size; next = END_NOT_FOUND; } -- 2.30.0 _______________________________________________ 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".
reply other threads:[~2022-10-20 3:43 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221020034325.77436-1-javashu2012@gmail.com \ --to=javashu2012@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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