From 62a65af71205afe6b5252619e5bba7eedfe3885c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 13:37:09 +0100 Subject: [PATCH] check the first two packets --- opustags.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/opustags.c b/opustags.c index 2d6b75b..c66c0a7 100644 --- a/opustags.c +++ b/opustags.c @@ -36,7 +36,6 @@ int main(int argc, char **argv){ continue; } // We got a page. - puts("got a page"); if(packet_count == -1){ // First page if(ogg_stream_init(&os, ogg_page_serialno(&og)) == -1){ error = "ogg_stream_init: unsuccessful"; @@ -50,7 +49,15 @@ int main(int argc, char **argv){ } if(ogg_stream_packetout(&os, &op) == 1){ packet_count++; - puts("got a packet"); + if(packet_count == 1){ // Identification header + if(strncmp((char*) op.packet, "OpusHead", 8) != 0) + error = "opustags: invalid identification header"; + } + if(packet_count == 2){ // Comment header + if(strncmp((char*) op.packet, "OpusTags", 8) != 0) + error = "opustags: invalid comment header"; + break; + } } if(ogg_stream_check(&os) != 0) error = "ogg_stream_check: internal error"; @@ -59,6 +66,8 @@ int main(int argc, char **argv){ ogg_stream_clear(&os); ogg_sync_clear(&oy); fclose(in); + if(!error && packet_count < 2) + error = "opustags: invalid file"; if(error){ fprintf(stderr, "%s\n", error); return EXIT_FAILURE;