diff mbox series

[FFmpeg-devel,1/4] avcodec/adts_parser: Don't presume buffer to be padded

Message ID GV1P250MB0737012990DC56B21EF2C0208FE72@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 6c812a80ddfadb3e69018971a2e92ace5326db36
Headers show
Series [FFmpeg-devel,1/4] avcodec/adts_parser: Don't presume buffer to be padded | expand

Commit Message

Andreas Rheinhardt May 10, 2024, 4:54 p.m. UTC
The documentation of av_adts_header_parse() does not require
the buffer to be padded at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/adts_parser.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt May 18, 2024, 4:59 p.m. UTC | #1
Andreas Rheinhardt:
> The documentation of av_adts_header_parse() does not require
> the buffer to be padded at all.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/adts_parser.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
> index 6c22c86ef2..81e2669149 100644
> --- a/libavcodec/adts_parser.c
> +++ b/libavcodec/adts_parser.c
> @@ -28,9 +28,14 @@
>  int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
>  {
>  #if CONFIG_ADTS_HEADER
> +    uint8_t tmpbuf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
>      GetBitContext gb;
>      AACADTSHeaderInfo hdr;
> -    int err = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
> +    int err;
> +    if (!buf)
> +        return AVERROR(EINVAL);
> +    memcpy(tmpbuf, buf, AV_AAC_ADTS_HEADER_SIZE);
> +    err = init_get_bits8(&gb, tmpbuf, AV_AAC_ADTS_HEADER_SIZE);
>      if (err < 0)
>          return err;
>      err = ff_adts_header_parse(&gb, &hdr);

Will apply this patchset with the remarks by Andrew and James addressed
tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
index 6c22c86ef2..81e2669149 100644
--- a/libavcodec/adts_parser.c
+++ b/libavcodec/adts_parser.c
@@ -28,9 +28,14 @@ 
 int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
 {
 #if CONFIG_ADTS_HEADER
+    uint8_t tmpbuf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
     GetBitContext gb;
     AACADTSHeaderInfo hdr;
-    int err = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
+    int err;
+    if (!buf)
+        return AVERROR(EINVAL);
+    memcpy(tmpbuf, buf, AV_AAC_ADTS_HEADER_SIZE);
+    err = init_get_bits8(&gb, tmpbuf, AV_AAC_ADTS_HEADER_SIZE);
     if (err < 0)
         return err;
     err = ff_adts_header_parse(&gb, &hdr);