diff mbox series

[FFmpeg-devel] flvdec: Check the avio_seek return value after reading a metadata packet

Message ID 30247c6c-5fe6-8131-d4e9-b6388846437d@sweelia.com
State New
Headers show
Series [FFmpeg-devel] flvdec: Check the avio_seek return value after reading a metadata packet | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Armstrong Huang June 19, 2023, 4 p.m. UTC
In most cases, flv_read_metabody reads pass the beginning of the meta_pos.
if the beginning of the meta_pos had been flushed from the IO buffer,
we would not be able to seek to the right position (for a nonseekable 
stream).

Is better to check the seek result and skip the current flv body if 
necessary, than to silently try to read from a
desynchronized stream that will only be interpreted as garbage.

Signed-off-by: Armstrong Huang <armstrong@sweelia.com>
---
  libavformat/flvdec.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)

          av_log(s, AV_LOG_DEBUG,
diff mbox series

Patch

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index d83edff727..9d2b0730f1 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -1096,7 +1096,14 @@  retry:
              } else if (type == TYPE_UNKNOWN) {
                  stream_type = FLV_STREAM_TYPE_DATA;
              }
-            avio_seek(s->pb, meta_pos, SEEK_SET);
+            if (avio_seek(s->pb, meta_pos, SEEK_SET) != meta_pos) {
+                // This can happen after flv_read_metabody
+                // above, on a non-seekable input, and the
+                // preceding data has been flushed out from
+                // the IO buffer.
+                av_log(s, AV_LOG_ERROR, "Unable to seek back to the flv 
tag body\n");
+                goto skip;
+            }
          }
      } else {