diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index b9fccec9ec..c797699859 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -150,6 +150,19 @@ mp2t_open(wtap *wth, int *err, gchar **err_info) return 0; } + if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { + return -1; + } + /* read the first 10 packets and make sure they all start with a sync byte */ + for (i = 0; i < 10; i++) { + bytes_read = file_read(buffer, sizeof(buffer), wth->fh); + if (bytes_read < 0) + return -1; /* read error */ + if (bytes_read < (int)sizeof(buffer)) + break; /* file has < 10 packets, that's ok if we're still in sync */ + if (buffer[0] != MP2T_SYNC_BYTE) + return 0; /* not a valid mpeg2 ts */ + } if (-1 == file_seek(wth->fh, first, SEEK_SET, err)) { return -1; }