From: Christos Zoulas Date: Wed, 2 Mar 2016 18:27:53 +0000 (+0000) Subject: PR/525: Fix ID3 indirect+offset handling. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2860cfad999e594da3ef42e84746598c1a141a29;p=file PR/525: Fix ID3 indirect+offset handling. --- diff --git a/ChangeLog b/ChangeLog index 8eff9d71..f5f0fbee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-03-01 13:28 Christos Zoulas + + * Fix ID3 indirect parsing + 2016-01-19 10:18 Christos Zoulas * add DER parsing capability diff --git a/src/softmagic.c b/src/softmagic.c index 160a987b..f3b8ea88 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.225 2016/01/19 15:08:50 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.226 2016/03/02 18:27:53 christos Exp $") #endif /* lint */ #include "magic.h" @@ -796,6 +796,18 @@ moffset(struct magic_set *ms, struct magic *m) } } +private uint32_t +cvt_id3(struct magic_set *ms, uint32_t v) +{ + v = ((((v >> 0) & 0x7f) << 0) | + (((v >> 8) & 0x7f) << 7) | + (((v >> 16) & 0x7f) << 14) | + (((v >> 24) & 0x7f) << 21)); + if ((ms->flags & MAGIC_DEBUG) != 0) + fprintf(stderr, "id3 offs=%u\n", v); + return v; +} + private int cvt_flip(int type, int flip) { @@ -1456,6 +1468,8 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, if (OFFSET_OOB(nbytes, offset, 4)) return 0; lhs = BE32(p); + if (in_type == FILE_BEID3) + lhs = cvt_id3(ms, lhs); if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: @@ -1493,6 +1507,8 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, if (OFFSET_OOB(nbytes, offset, 4)) return 0; lhs = LE32(p); + if (in_type == FILE_LEID3) + lhs = cvt_id3(ms, lhs); if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: @@ -1600,20 +1616,6 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, break; } - switch (in_type) { - case FILE_LEID3: - case FILE_BEID3: - offset = ((((offset >> 0) & 0x7f) << 0) | - (((offset >> 8) & 0x7f) << 7) | - (((offset >> 16) & 0x7f) << 14) | - (((offset >> 24) & 0x7f) << 21)); - if ((ms->flags & MAGIC_DEBUG) != 0) - fprintf(stderr, "id3 offs=%u\n", offset); - break; - default: - break; - } - if (m->flag & INDIROFFADD) { offset += ms->c.li[cont_level-1].off; if (offset == 0) {