Commit f6a708f0 authored by Reimar Döffinger's avatar Reimar Döffinger

Use get_le32/get_be32 in wc3movie demuxer instead of reading everything into

a buffer first.

Originally committed as revision 18444 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 147a90a3
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avformat.h" #include "avformat.h"
#define WC3_PREAMBLE_SIZE 8
#define FORM_TAG MKTAG('F', 'O', 'R', 'M') #define FORM_TAG MKTAG('F', 'O', 'R', 'M')
#define MOVE_TAG MKTAG('M', 'O', 'V', 'E') #define MOVE_TAG MKTAG('M', 'O', 'V', 'E')
#define PC__TAG MKTAG('_', 'P', 'C', '_') #define PC__TAG MKTAG('_', 'P', 'C', '_')
...@@ -131,7 +129,6 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -131,7 +129,6 @@ static int wc3_read_header(AVFormatContext *s,
unsigned int fourcc_tag; unsigned int fourcc_tag;
unsigned int size; unsigned int size;
AVStream *st; AVStream *st;
unsigned char preamble[WC3_PREAMBLE_SIZE];
char buffer[513]; char buffer[513];
int ret = 0; int ret = 0;
int current_palette = 0; int current_palette = 0;
...@@ -152,11 +149,8 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -152,11 +149,8 @@ static int wc3_read_header(AVFormatContext *s,
/* traverse through the chunks and load the header information before /* traverse through the chunks and load the header information before
* the first BRCH tag */ * the first BRCH tag */
if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != fourcc_tag = get_le32(pb);
WC3_PREAMBLE_SIZE) size = (get_be32(pb) + 1) & (~1);
return AVERROR(EIO);
fourcc_tag = AV_RL32(&preamble[0]);
size = (AV_RB32(&preamble[4]) + 1) & (~1);
do { do {
switch (fourcc_tag) { switch (fourcc_tag) {
...@@ -170,9 +164,7 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -170,9 +164,7 @@ static int wc3_read_header(AVFormatContext *s,
case PC__TAG: case PC__TAG:
/* need the number of palettes */ /* need the number of palettes */
url_fseek(pb, 8, SEEK_CUR); url_fseek(pb, 8, SEEK_CUR);
if ((ret = get_buffer(pb, preamble, 4)) != 4) wc3->palette_count = get_le32(pb);
return AVERROR(EIO);
wc3->palette_count = AV_RL32(&preamble[0]);
if((unsigned)wc3->palette_count >= UINT_MAX / PALETTE_SIZE){ if((unsigned)wc3->palette_count >= UINT_MAX / PALETTE_SIZE){
wc3->palette_count= 0; wc3->palette_count= 0;
return -1; return -1;
...@@ -194,11 +186,8 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -194,11 +186,8 @@ static int wc3_read_header(AVFormatContext *s,
case SIZE_TAG: case SIZE_TAG:
/* video resolution override */ /* video resolution override */
if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != wc3->width = get_le32(pb);
WC3_PREAMBLE_SIZE) wc3->height = get_le32(pb);
return AVERROR(EIO);
wc3->width = AV_RL32(&preamble[0]);
wc3->height = AV_RL32(&preamble[4]);
break; break;
case PALT_TAG: case PALT_TAG:
...@@ -224,18 +213,17 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -224,18 +213,17 @@ static int wc3_read_header(AVFormatContext *s,
default: default:
av_log(s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n", av_log(s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
preamble[0], preamble[1], preamble[2], preamble[3], (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
preamble[0], preamble[1], preamble[2], preamble[3]); (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
break; break;
} }
if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != fourcc_tag = get_le32(pb);
WC3_PREAMBLE_SIZE)
return AVERROR(EIO);
fourcc_tag = AV_RL32(&preamble[0]);
/* chunk sizes are 16-bit aligned */ /* chunk sizes are 16-bit aligned */
size = (AV_RB32(&preamble[4]) + 1) & (~1); size = (get_be32(pb) + 1) & (~1);
if (url_feof(pb))
return AVERROR(EIO);
} while (fourcc_tag != BRCH_TAG); } while (fourcc_tag != BRCH_TAG);
...@@ -281,7 +269,6 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -281,7 +269,6 @@ static int wc3_read_packet(AVFormatContext *s,
unsigned int size; unsigned int size;
int packet_read = 0; int packet_read = 0;
int ret = 0; int ret = 0;
unsigned char preamble[WC3_PREAMBLE_SIZE];
unsigned char text[1024]; unsigned char text[1024];
unsigned int palette_number; unsigned int palette_number;
int i; int i;
...@@ -290,14 +277,11 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -290,14 +277,11 @@ static int wc3_read_packet(AVFormatContext *s,
while (!packet_read) { while (!packet_read) {
/* get the next chunk preamble */ fourcc_tag = get_le32(pb);
if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
WC3_PREAMBLE_SIZE)
return AVERROR(EIO);
fourcc_tag = AV_RL32(&preamble[0]);
/* chunk sizes are 16-bit aligned */ /* chunk sizes are 16-bit aligned */
size = (AV_RB32(&preamble[4]) + 1) & (~1); size = (get_be32(pb) + 1) & (~1);
if (url_feof(pb))
return AVERROR(EIO);
switch (fourcc_tag) { switch (fourcc_tag) {
...@@ -307,9 +291,7 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -307,9 +291,7 @@ static int wc3_read_packet(AVFormatContext *s,
case SHOT_TAG: case SHOT_TAG:
/* load up new palette */ /* load up new palette */
if ((ret = get_buffer(pb, preamble, 4)) != 4) palette_number = get_le32(pb);
return AVERROR(EIO);
palette_number = AV_RL32(&preamble[0]);
if (palette_number >= wc3->palette_count) if (palette_number >= wc3->palette_count)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
base_palette_index = palette_number * PALETTE_COUNT * 3; base_palette_index = palette_number * PALETTE_COUNT * 3;
...@@ -367,8 +349,8 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -367,8 +349,8 @@ static int wc3_read_packet(AVFormatContext *s,
default: default:
av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n", av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
preamble[0], preamble[1], preamble[2], preamble[3], (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
preamble[0], preamble[1], preamble[2], preamble[3]); (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
packet_read = 1; packet_read = 1;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment