avformat/mods: Return EOF for packets starting at the index offset
Assuming there is no padding between the last packet and the index, this prevents the index from being parsed as a normal packet, with non- sensical data.
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
#include "demux.h"
|
||||
#include "internal.h"
|
||||
|
||||
typedef struct MODSDemuxContext {
|
||||
uint32_t index_pos;
|
||||
} MODSDemuxContext;
|
||||
|
||||
static int mods_probe(const AVProbeData *p)
|
||||
{
|
||||
if (memcmp(p->buf, "MODSN3\x0a\x00", 8))
|
||||
@@ -44,6 +48,7 @@ static int mods_probe(const AVProbeData *p)
|
||||
static int mods_read_header(AVFormatContext *s)
|
||||
{
|
||||
AVIOContext *pb = s->pb;
|
||||
MODSDemuxContext *ctx = s->priv_data;
|
||||
AVRational fps;
|
||||
int64_t pos;
|
||||
int64_t timestamp;
|
||||
@@ -72,6 +77,7 @@ static int mods_read_header(AVFormatContext *s)
|
||||
pos = avio_rl32(pb);
|
||||
num_keyframes = avio_rl32(pb);
|
||||
avio_seek(pb, pos, SEEK_SET);
|
||||
ctx->index_pos = pos;
|
||||
|
||||
for (int i = 0; i < num_keyframes; ++i) {
|
||||
timestamp = avio_rl32(pb);
|
||||
@@ -94,6 +100,7 @@ static int mods_read_header(AVFormatContext *s)
|
||||
static int mods_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
{
|
||||
AVIOContext *pb = s->pb;
|
||||
MODSDemuxContext *ctx = s->priv_data;
|
||||
unsigned size;
|
||||
int64_t pos;
|
||||
int ret;
|
||||
@@ -102,7 +109,11 @@ static int mods_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
if (avio_feof(pb))
|
||||
return AVERROR_EOF;
|
||||
|
||||
/* This assumes the keyframes index directly follows the last packet. */
|
||||
pos = avio_tell(pb);
|
||||
if (pos == ctx->index_pos)
|
||||
return AVERROR_EOF;
|
||||
|
||||
size = avio_rl32(pb) >> 14;
|
||||
ret = av_get_packet(pb, pkt, size);
|
||||
pkt->pos = pos;
|
||||
@@ -120,6 +131,7 @@ const FFInputFormat ff_mods_demuxer = {
|
||||
.p.long_name = NULL_IF_CONFIG_SMALL("MobiClip MODS"),
|
||||
.p.extensions = "mods",
|
||||
.p.flags = AVFMT_GENERIC_INDEX,
|
||||
.priv_data_size = sizeof(MODSDemuxContext),
|
||||
.read_probe = mods_probe,
|
||||
.read_header = mods_read_header,
|
||||
.read_packet = mods_read_packet,
|
||||
|
||||
Reference in New Issue
Block a user