[FFmpeg-devel] [PATCH] Mark truncated packets as corrupt in av_get_packet.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Tue May 1 19:36:35 CEST 2012
Manually remove that flag again for formats that read an arbitrary
amount of data and thus truncation is not an error.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
libavformat/aiffdec.c | 2 ++
libavformat/apc.c | 1 +
libavformat/au.c | 1 +
libavformat/mp3dec.c | 1 +
libavformat/pcmdec.c | 1 +
libavformat/rsodec.c | 1 +
libavformat/sol.c | 1 +
libavformat/soxdec.c | 1 +
libavformat/utils.c | 3 +++
9 files changed, 12 insertions(+)
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index c94863c..4083316 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -322,6 +322,8 @@ static int aiff_read_packet(AVFormatContext *s,
if (res < 0)
return res;
+ if (size >= st->codec->block_align)
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
/* Only one stream in an AIFF file */
pkt->stream_index = 0;
pkt->duration = (res / st->codec->block_align) * aiff->block_duration;
diff --git a/libavformat/apc.c b/libavformat/apc.c
index 389eba7..2e160cc 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -76,6 +76,7 @@ static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
return AVERROR(EIO);
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
return 0;
}
diff --git a/libavformat/au.c b/libavformat/au.c
index aa52a96..4dd84bf 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -187,6 +187,7 @@ static int au_read_packet(AVFormatContext *s,
av_get_bits_per_sample(s->streams[0]->codec->codec_id) >> 3);
if (ret < 0)
return ret;
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 31d64b2..edfee16 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -175,6 +175,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
ret= av_get_packet(s->pb, pkt, size);
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
if (ret <= 0) {
if(ret<0)
diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index eacac2f..94f6b4a 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -36,6 +36,7 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
ret= av_get_packet(s->pb, pkt, size);
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
if (ret < 0)
return ret;
diff --git a/libavformat/rsodec.c b/libavformat/rsodec.c
index 1886116..3933fc0 100644
--- a/libavformat/rsodec.c
+++ b/libavformat/rsodec.c
@@ -80,6 +80,7 @@ static int rso_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0)
return ret;
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last packet */
diff --git a/libavformat/sol.c b/libavformat/sol.c
index 698502e..b2ecd82 100644
--- a/libavformat/sol.c
+++ b/libavformat/sol.c
@@ -133,6 +133,7 @@ static int sol_read_packet(AVFormatContext *s,
ret= av_get_packet(s->pb, pkt, MAX_SIZE);
if (ret < 0)
return ret;
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last
diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c
index 9ca7673..a0b65d9 100644
--- a/libavformat/soxdec.c
+++ b/libavformat/soxdec.c
@@ -138,6 +138,7 @@ static int sox_read_packet(AVFormatContext *s,
ret = av_get_packet(s->pb, pkt, size);
if (ret < 0)
return AVERROR(EIO);
+ pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
pkt->stream_index = 0;
pkt->size = ret;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d6e7f69..d9dc2fb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -297,6 +297,7 @@ int ffio_limit(AVIOContext *s, int size)
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
{
int ret;
+ int orig_size = size;
size= ffio_limit(s, size);
ret= av_new_packet(pkt, size);
@@ -311,6 +312,8 @@ int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
av_free_packet(pkt);
else
av_shrink_packet(pkt, ret);
+ if (pkt->size < orig_size)
+ pkt->flags |= AV_PKT_FLAG_CORRUPT;
return ret;
}
--
1.7.10
More information about the ffmpeg-devel
mailing list