diff options
author | Mike Melanson <mike@multimedia.cx> | 2002-11-01 03:36:24 +0000 |
---|---|---|
committer | Mike Melanson <mike@multimedia.cx> | 2002-11-01 03:36:24 +0000 |
commit | 2eab203a28f7f3ee7f851fa5b4b98d5c9537e4d9 (patch) | |
tree | 1efc4cd0b992269a029ec6a7c6760d16d26bb674 | |
parent | 244b2cd15d09de53613243386b274a474284e2d2 (diff) | |
download | xine-lib-2eab203a28f7f3ee7f851fa5b4b98d5c9537e4d9.tar.gz xine-lib-2eab203a28f7f3ee7f851fa5b4b98d5c9537e4d9.tar.bz2 |
move file signature validation to open_file() functions
CVS patchset: 3121
CVS date: 2002/11/01 03:36:24
-rw-r--r-- | src/demuxers/demux_idcin.c | 97 | ||||
-rw-r--r-- | src/demuxers/demux_roq.c | 36 | ||||
-rw-r--r-- | src/demuxers/demux_wc3movie.c | 24 |
3 files changed, 53 insertions, 104 deletions
diff --git a/src/demuxers/demux_idcin.c b/src/demuxers/demux_idcin.c index 28dd3812d..58fef2806 100644 --- a/src/demuxers/demux_idcin.c +++ b/src/demuxers/demux_idcin.c @@ -63,7 +63,7 @@ * - if any bytes exceed 63, do not shift the bytes at all before * transmitting them to the video decoder * - * $Id: demux_idcin.c,v 1.24 2002/10/30 00:29:30 tmmm Exp $ + * $Id: demux_idcin.c,v 1.25 2002/11/01 03:36:24 tmmm Exp $ */ #ifdef HAVE_CONFIG_H @@ -133,7 +133,6 @@ static int demux_idcin_send_chunk(demux_plugin_t *this_gen) { demux_idcin_t *this = (demux_idcin_t *) this_gen; buf_element_t *buf = NULL; unsigned int command; - off_t current_file_pos; unsigned char preamble[8]; unsigned char disk_palette[PALETTE_SIZE * 3]; palette_entry_t palette[PALETTE_SIZE]; @@ -143,8 +142,6 @@ static int demux_idcin_send_chunk(demux_plugin_t *this_gen) { int current_audio_chunk = 1; int scale_bits; - current_file_pos = this->input->get_current_pos(this->input); - /* figure out what the next data is */ if (this->input->read(this->input, (unsigned char *)&command, 4) != 4) { this->status = DEMUX_FINISHED; @@ -279,16 +276,49 @@ static int open_idcin_file(demux_idcin_t *this) { unsigned char header[IDCIN_HEADER_SIZE]; this->input->seek(this->input, 0, SEEK_SET); - if (this->input->read(this->input, header, IDCIN_HEADER_SIZE) != + if (this->input->read(this->input, header, IDCIN_HEADER_SIZE) != IDCIN_HEADER_SIZE) return 0; + /* + * This is what you could call a "probabilistic" file check: Id CIN + * files don't have a definite file signature. In lieu of such a marker, + * perform sanity checks on the 5 header fields: + * width, height: greater than 0, less than or equal to 1024 + * audio sample rate: greater than or equal to 8000, less than or + * equal to 48000, or 0 for no audio + * audio sample width (bytes/sample): 0 for no audio, or 1 or 2 + * audio channels: 0 for no audio, or 1 or 2 + */ + + /* check the width */ this->video_width = LE_32(&header[0]); + if ((this->video_width == 0) || (this->video_width > 1024)) + return 0; + + /* check the height */ this->video_height = LE_32(&header[4]); + if ((this->video_height == 0) || (this->video_height > 1024)) + return 0; + + /* check the audio sample rate */ this->audio_sample_rate = LE_32(&header[8]); + if ((this->audio_sample_rate != 0) && + ((this->audio_sample_rate < 8000) || (this->audio_sample_rate > 48000))) + return 0; + + /* check the audio bytes/sample */ this->audio_bytes_per_sample = LE_32(&header[12]); + if (this->audio_bytes_per_sample > 2) + return 0; + + /* check the audio channels */ this->audio_channels = LE_32(&header[16]); - this->filesize = this->input->get_length(this->input); + if (this->audio_channels > 2) + return 0; + + /* if execution got this far, qualify it as a valid Id CIN file + * and continue loading */ /* read the Huffman table */ if (this->input->read(this->input, this->huffman_table, @@ -419,8 +449,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str input_plugin_t *input = (input_plugin_t *) input_gen; demux_idcin_t *this; - char header[IDCIN_HEADER_SIZE]; - unsigned int current_value; if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { printf(_("demux_idcin.c: input not seekable, can not handle!\n")); @@ -445,59 +473,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str case METHOD_BY_CONTENT: - input->seek(input, 0, SEEK_SET); - if (input->read(input, header, IDCIN_HEADER_SIZE) != IDCIN_HEADER_SIZE) - return DEMUX_CANNOT_HANDLE; - - /* - * This is what you could call a "probabilistic" file check: Id CIN - * files don't have a definite file signature. In lieu of such a marker, - * perform sanity checks on the 5 header fields: - * width, height: greater than 0, less than or equal to 1024 - * audio sample rate: greater than or equal to 8000, less than or - * equal to 48000, or 0 for no audio - * audio sample width (bytes/sample): 0 for no audio, or 1 or 2 - * audio channels: 0 for no audio, or 1 or 2 - */ - - /* check the width */ - current_value = LE_32(&header[0]); - if ((current_value == 0) || (current_value > 1024)) { - free (this); - return NULL; - } - - /* check the height */ - current_value = LE_32(&header[4]); - if ((current_value == 0) || (current_value > 1024)) { - free (this); - return NULL; - } - - /* check the audio sample rate */ - current_value = LE_32(&header[8]); - if ((current_value != 0) && - ((current_value < 8000) || (current_value > 48000))) { - free (this); - return NULL; - } - - /* check the audio bytes/sample */ - current_value = LE_32(&header[12]); - if (current_value > 2) { - free (this); - return NULL; - } - - /* check the audio channels */ - current_value = LE_32(&header[16]); - if (current_value > 2) { - free (this); - return NULL; - } - - /* if execution got this far, qualify it as a valid Id CIN file - * and load it */ if (!open_idcin_file(this)) { free (this); return NULL; diff --git a/src/demuxers/demux_roq.c b/src/demuxers/demux_roq.c index fc7212a8f..4f13473e8 100644 --- a/src/demuxers/demux_roq.c +++ b/src/demuxers/demux_roq.c @@ -21,7 +21,7 @@ * For more information regarding the RoQ file format, visit: * http://www.csse.monash.edu.au/~timf/ * - * $Id: demux_roq.c,v 1.26 2002/10/28 03:24:43 miguelfreitas Exp $ + * $Id: demux_roq.c,v 1.27 2002/11/01 03:36:24 tmmm Exp $ */ #ifdef HAVE_CONFIG_H @@ -94,13 +94,16 @@ static int open_roq_file(demux_roq_t *this) { unsigned int chunk_type; unsigned int chunk_size; - this->status = DEMUX_OK; - this->input->seek(this->input, 0, SEEK_SET); if (this->input->read(this->input, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return 0; + /* check for the RoQ magic numbers */ + if ((LE_16(&preamble[0]) != RoQ_MAGIC_NUMBER) || + (LE_32(&preamble[2]) != 0xFFFFFFFF)) + return 0; + this->width = this->height = 0; this->audio_channels = 0; /* assume no audio at first */ @@ -392,7 +395,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str input_plugin_t *input = (input_plugin_t *) input_gen; demux_roq_t *this; - char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { printf(_("demux_roq.c: input not seekable, can not handle!\n")); @@ -417,32 +419,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str case METHOD_BY_CONTENT: - input->seek(input, 0, SEEK_SET); - if (input->read(input, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != - RoQ_CHUNK_PREAMBLE_SIZE) { - free (this); - return NULL; - } - -#if 0 - printf ("demux_roq: %02x %02x %02x %02x %02x %02x %02x %02x \n", - preamble[0], - preamble[1], - preamble[2], - preamble[3], - preamble[4], - preamble[5], - preamble[6], - preamble[7]); -#endif - - /* check for the RoQ magic numbers */ - if ((LE_16(&preamble[0]) != RoQ_MAGIC_NUMBER) || - (LE_32(&preamble[2]) != 0xFFFFFFFF)) { - free (this); - return NULL; - } - if (!open_roq_file(this)) { free (this); return NULL; diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c index 8b938350b..7d3f070c1 100644 --- a/src/demuxers/demux_wc3movie.c +++ b/src/demuxers/demux_wc3movie.c @@ -22,7 +22,7 @@ * For more information on the MVE file format, visit: * http://www.pcisys.net/~melanson/codecs/ * - * $Id: demux_wc3movie.c,v 1.22 2002/10/31 02:22:58 tmmm Exp $ + * $Id: demux_wc3movie.c,v 1.23 2002/11/01 03:36:24 tmmm Exp $ */ #ifdef HAVE_CONFIG_H @@ -381,11 +381,21 @@ static int open_mve_file(demux_mve_t *this) { int i, j; unsigned char r, g, b; int temp; + unsigned char header[16]; /* these are the frame dimensions unless others are found */ this->video_width = WC3_USUAL_WIDTH; this->video_height = WC3_USUAL_HEIGHT; + this->input->seek(this->input, 0, SEEK_SET); + if (this->input->read(this->input, header, 16) != 16) + return 0; + + if ((BE_32(&header[0]) != FORM_TAG) || + (BE_32(&header[8]) != MOVE_TAG) || + (BE_32(&header[12]) != PC_TAG)) + return 0; + /* load the number of palettes, the only interesting piece of information * in the _PC_ chunk; take it for granted that it will always appear at * position 0x1C */ @@ -651,7 +661,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str input_plugin_t *input = (input_plugin_t *) input_gen; demux_mve_t *this; - unsigned char header[16]; if (! (input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) { printf(_("demux_mve.c: input not seekable, can not handle!\n")); @@ -676,17 +685,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str case METHOD_BY_CONTENT: - input->seek(input, 0, SEEK_SET); - if (input->read(input, header, 16) != 16) - return DEMUX_CANNOT_HANDLE; - - if ((BE_32(&header[0]) != FORM_TAG) || - (BE_32(&header[8]) != MOVE_TAG) || - (BE_32(&header[12]) != PC_TAG)) { - free (this); - return NULL; - } - if (!open_mve_file(this)) { free (this); return NULL; |