* [FFmpeg-devel] [PATCH v1] avcodec/sbc_parser: Fix parser error when reading data slowly.
@ 2022-10-20 3:43 javashu2012
0 siblings, 0 replies; only message in thread
From: javashu2012 @ 2022-10-20 3:43 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: bevis
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".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-20 3:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20 3:43 [FFmpeg-devel] [PATCH v1] avcodec/sbc_parser: Fix parser error when reading data slowly javashu2012
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