aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-03-29 03:18:45 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-03-29 03:50:25 +0100
commit067ada04d19629fb0afefffda27bcd5ebdffc0e8 (patch)
treee77ee59a67fc5d26cb236352138a25de082df4a8 /libavcodec
parent657cee1aef724377710cef26915c09ea50bd5fcd (diff)
downloadffmpeg-067ada04d19629fb0afefffda27bcd5ebdffc0e8.tar.gz
avcodec/xbmdec: redesign parser to handle more cases
The new code is more tolerant on the syntax Fixes decoding of bm1.xbm Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/xbmdec.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c
index 203c2f9cbe..a2c36595e9 100644
--- a/libavcodec/xbmdec.c
+++ b/libavcodec/xbmdec.c
@@ -37,6 +37,27 @@ static int convert(uint8_t x)
return x;
}
+static int parse_str_int(const uint8_t *p, int len, const uint8_t *key)
+{
+ const uint8_t *end = p + len;
+
+ for(; p<end - strlen(key); p++) {
+ if (!memcmp(p, key, strlen(key)))
+ break;
+ }
+ p += strlen(key);
+ if (p >= end)
+ return INT_MIN;
+
+ for(; p<end; p++) {
+ char **eptr;
+ int64_t ret = strtol(p, &eptr, 10);
+ if (eptr != p)
+ return ret;
+ }
+ return INT_MIN;
+}
+
static int xbm_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
@@ -45,34 +66,14 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data,
int width = 0;
int height = 0;
const uint8_t *end, *ptr = avpkt->data;
+ const uint8_t *next;
uint8_t *dst;
avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
end = avpkt->data + avpkt->size;
- while (!width || !height) {
- char name[256];
- int number, len;
-
- ptr += strcspn(ptr, "#");
- if (ptr >= avpkt->data + avpkt->size) {
- av_log(avctx, AV_LOG_ERROR, "End of file reached.\n");
- return AVERROR_INVALIDDATA;
- }
- if (sscanf(ptr, "#define %255s %u", name, &number) != 2) {
- av_log(avctx, AV_LOG_ERROR, "Unexpected preprocessor directive\n");
- return AVERROR_INVALIDDATA;
- }
- len = strlen(name);
- if ((len > 6) && !height && !memcmp(name + len - 7, "_height", 7)) {
- height = number;
- } else if ((len > 5) && !width && !memcmp(name + len - 6, "_width", 6)) {
- width = number;
- } else {
- av_log(avctx, AV_LOG_WARNING, "Unknown define '%s'\n", name);
- }
- ptr += strcspn(ptr, "\n\r") + 1;
- }
+ width = parse_str_int(avpkt->data, avpkt->size, "_width");
+ height = parse_str_int(avpkt->data, avpkt->size, "_height");
if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
return ret;
@@ -81,7 +82,12 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data,
return ret;
// goto start of image data
- ptr += strcspn(ptr, "{") + 1;
+ next = ptr + strcspn(ptr, "{");
+ if (!*next)
+ next = ptr + strcspn(ptr, "(");
+ if (!*next)
+ return AVERROR_INVALIDDATA;
+ ptr = next + 1;
linesize = (avctx->width + 7) / 8;
for (i = 0; i < avctx->height; i++) {
@@ -89,7 +95,7 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data,
for (j = 0; j < linesize; j++) {
uint8_t val;
- ptr += strcspn(ptr, "x") + 1;
+ ptr += strcspn(ptr, "x$") + 1;
if (ptr < end && av_isxdigit(*ptr)) {
val = convert(*ptr++);
if (av_isxdigit(*ptr))