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 D4F1F43F64 for ; Thu, 20 Oct 2022 03:43:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C397B68BCFC; Thu, 20 Oct 2022 06:43:48 +0300 (EEST) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F83868B1E1 for ; Thu, 20 Oct 2022 06:43:42 +0300 (EEST) Received: by mail-pj1-f49.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so1832019pjf.5 for ; Wed, 19 Oct 2022 20:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=do0kxa8ZpUB45ofKXjFBREpDKcobaSQPY13t5fy7x14=; b=b62XhRhSQH0SyKOMZ9zLd9T84WEBAqQQ+LtzIGZA2ZgJh+eX3esPi6ryP3VZiZSyle vZ54hGMUSzLuEE0NHDSZNcX2GFjDZn8CFM1OvoEXq6W2/+tudr6uU6kGBxuUyHS3mSEP N/bXJBH95PkjBGh5hsOty5eJd1wwK1YaJ+7m7v/s7b0bnT5DOK+GJEqBSIOcna07M3AX +PZjuHLuq0XbDKU3DgMo4UfrPpuRucXMdXnmWf0627FtYZtYkA67KmiMDZJT+zaV7r4s MSLtinWrubt/YdKKND2HjXL4nFvWyg+L18kzD1FjTwdTs/HF7KsJGHBIL65wfCKpJHwg Ncrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=do0kxa8ZpUB45ofKXjFBREpDKcobaSQPY13t5fy7x14=; b=dIcBGwQV1TIB74X622+2OYssPN0a4mATOugwRGl1m8IpFjIaCgawEiNdR9C8ajQBA4 iSTrU/LyHJ+Nq8ux18BarRTS3njzFmyx/mVzkVQSEGDWI5VrQp0PsnZclbHcablYs4Nl Eedgi7/UAr+duPGB/m+EqqheDHL97rOn6/1aNEvsBSe+ZAQVQdK7v2YgdrO6MXwCiADC yUX/zlo5C2LX901GMCN7EAvHMZDJDFEtYjwZk2TEUCEr1lw5Knj5pv+tqQs6fTG+hvLe TEusF4gdW7+/xP49KWjhIRVGXoXI0Tys7C3By0vLJQjUAddDxs3VtR8N+d6Dsr8HXlxP bELg== X-Gm-Message-State: ACrzQf1/MCEvX6u1lZsXHZpVKUGJkutv9K6sO2jcpncDBgvxOR/ZFC79 npCT3DFfnVb/EwbXTw+dASD/eZZqgczzyQ== X-Google-Smtp-Source: AMsMyM7aZ7Tv3xfquhQ01zS9NRLLc54ennzyZPUuHmXLzXGKxe0P6XIDfMxySinLQiCWOZ3rj0MUKg== X-Received: by 2002:a17:902:820a:b0:178:456e:138 with SMTP id x10-20020a170902820a00b00178456e0138mr11923768pln.145.1666237419650; Wed, 19 Oct 2022 20:43:39 -0700 (PDT) Received: from localhost.localdomain ([47.246.98.56]) by smtp.gmail.com with ESMTPSA id m13-20020a654c8d000000b0041c35462316sm10749397pgt.26.2022.10.19.20.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 20:43:39 -0700 (PDT) From: javashu2012@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Oct 2022 11:43:25 +0800 Message-Id: <20221020034325.77436-1-javashu2012@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1] avcodec/sbc_parser: Fix parser error when reading data slowly. 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 Cc: bevis Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: bevis 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 --- 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".