[FFmpeg-devel] [PATCH 2/4] avformat: Use ffio_read_size where appropriate

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Feb 3 12:27:47 EET 2021


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/aaxdec.c  | 9 +++------
 libavformat/act.c     | 9 +++------
 libavformat/kvag.c    | 5 ++---
 libavformat/nuv.c     | 7 ++++---
 libavformat/pva.c     | 7 ++++---
 libavformat/riffdec.c | 6 +++---
 libavformat/utils.c   | 6 +++---
 libavformat/wavdec.c  | 8 ++++----
 8 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index 7d10e805ca..45648532d6 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -22,6 +22,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 
 typedef struct AAXColumn {
@@ -219,13 +220,9 @@ static int aax_read_header(AVFormatContext *s)
     }
 
     avio_seek(pb, a->strings_offset, SEEK_SET);
-    ret = avio_read(pb, a->string_table, a->strings_size);
-    if (ret != a->strings_size) {
-        if (ret < 0)
-            goto fail;
-        ret = AVERROR(EIO);
+    ret = ffio_read_size(pb, a->string_table, a->strings_size);
+    if (ret < 0)
         goto fail;
-    }
 
     for (int c = 0; c < a->columns; c++) {
         int64_t data_offset = 0;
diff --git a/libavformat/act.c b/libavformat/act.c
index 26425ca1bb..9e72bba21c 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
+#include "avio_internal.h"
 #include "riff.h"
 #include "internal.h"
 #include "libavcodec/get_bits.h"
@@ -126,12 +127,10 @@ static int read_packet(AVFormatContext *s,
 
     if(s->streams[0]->codecpar->sample_rate==4400 && !ctx->second_packet)
     {
-        ret = avio_read(pb, ctx->audio_buffer, frame_size);
+        ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
 
         if(ret<0)
             return ret;
-        if(ret!=frame_size)
-            return AVERROR(EIO);
 
         pkt->data[0]=ctx->audio_buffer[11];
         pkt->data[1]=ctx->audio_buffer[0];
@@ -165,12 +164,10 @@ static int read_packet(AVFormatContext *s,
     }
     else // 8000 Hz
     {
-        ret = avio_read(pb, ctx->audio_buffer, frame_size);
+        ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
 
         if(ret<0)
             return ret;
-        if(ret!=frame_size)
-            return AVERROR(EIO);
 
         pkt->data[0]=ctx->audio_buffer[5];
         pkt->data[1]=ctx->audio_buffer[0];
diff --git a/libavformat/kvag.c b/libavformat/kvag.c
index 8f641873b9..524cb3870c 100644
--- a/libavformat/kvag.c
+++ b/libavformat/kvag.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 #include "rawenc.h"
 #include "libavutil/intreadwrite.h"
@@ -55,10 +56,8 @@ static int kvag_read_header(AVFormatContext *s)
     if (!(st = avformat_new_stream(s, NULL)))
         return AVERROR(ENOMEM);
 
-    if ((ret = avio_read(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
+    if ((ret = ffio_read_size(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
         return ret;
-    else if (ret != KVAG_HEADER_SIZE)
-        return AVERROR(EIO);
 
     hdr.magic                   = AV_RL32(buf +  0);
     hdr.data_size               = AV_RL32(buf +  4);
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index df90df4938..6bfdd3e82f 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -24,6 +24,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 #include "riff.h"
 
@@ -258,9 +259,9 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt)
         int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0;
         uint64_t pos    = avio_tell(pb);
 
-        ret = avio_read(pb, hdr, HDRSIZE);
-        if (ret < HDRSIZE)
-            return ret < 0 ? ret : AVERROR(EIO);
+        ret = ffio_read_size(pb, hdr, HDRSIZE);
+        if (ret < 0)
+            return ret;
 
         frametype = hdr[0];
         size      = PKTSIZE(AV_RL32(&hdr[8]));
diff --git a/libavformat/pva.c b/libavformat/pva.c
index 58ec78750c..89b8608766 100644
--- a/libavformat/pva.c
+++ b/libavformat/pva.c
@@ -20,6 +20,7 @@
  */
 
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 #include "mpeg.h"
 
@@ -147,9 +148,9 @@ recover:
                 goto recover;
             }
 
-            ret = avio_read(pb, pes_header_data, pes_header_data_length);
-            if (ret != pes_header_data_length)
-                return ret < 0 ? ret : AVERROR_INVALIDDATA;
+            ret = ffio_read_size(pb, pes_header_data, pes_header_data_length);
+            if (ret < 0)
+                return ret;
             length -= 9 + pes_header_data_length;
 
             pes_packet_length -= 3 + pes_header_data_length;
diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 533bb5a15d..c04dec6f57 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -33,10 +33,10 @@ int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
 {
     int ret;
     av_assert0(sizeof(*g) == 16); //compiler will optimize this out
-    ret = avio_read(s, *g, sizeof(*g));
-    if (ret < (int)sizeof(*g)) {
+    ret = ffio_read_size(s, *g, sizeof(*g));
+    if (ret < 0) {
         memset(*g, 0, sizeof(*g));
-        return ret < 0 ? ret : AVERROR_INVALIDDATA;
+        return ret;
     }
     return 0;
 }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index fb3299503e..2bffadb6b9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3306,12 +3306,12 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb
     int ret = ff_alloc_extradata(par, size);
     if (ret < 0)
         return ret;
-    ret = avio_read(pb, par->extradata, size);
-    if (ret != size) {
+    ret = ffio_read_size(pb, par->extradata, size);
+    if (ret < 0) {
         av_freep(&par->extradata);
         par->extradata_size = 0;
         av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size);
-        return ret < 0 ? ret : AVERROR_INVALIDDATA;
+        return ret;
     }
 
     return ret;
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 256c36ebe2..7de4c9df97 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -236,8 +236,8 @@ static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
     int ret;
 
     av_assert0(length < sizeof(temp));
-    if ((ret = avio_read(s->pb, temp, length)) != length)
-        return ret < 0 ? ret : AVERROR_INVALIDDATA;
+    if ((ret = ffio_read_size(s->pb, temp, length)) < 0)
+        return ret;
 
     temp[length] = 0;
 
@@ -306,9 +306,9 @@ static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
         if (!(coding_history = av_malloc(size + 1)))
             return AVERROR(ENOMEM);
 
-        if ((ret = avio_read(s->pb, coding_history, size)) != size) {
+        if ((ret = ffio_read_size(s->pb, coding_history, size)) < 0) {
             av_free(coding_history);
-            return ret < 0 ? ret : AVERROR_INVALIDDATA;
+            return ret;
         }
 
         coding_history[size] = 0;
-- 
2.27.0



More information about the ffmpeg-devel mailing list