--- embedaddon/php/ext/fileinfo/libmagic/ascmagic.c 2012/05/29 12:34:39 1.1.1.2 +++ embedaddon/php/ext/fileinfo/libmagic/ascmagic.c 2013/07/22 01:31:50 1.1.1.3 @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: ascmagic.c,v 1.84 2011/12/08 12:38:24 rrt Exp $") +FILE_RCSID("@(#)$File: ascmagic.c,v 1.85 2012/08/09 16:33:15 christos Exp $") #endif /* lint */ #include "magic.h" @@ -134,13 +134,15 @@ file_ascmagic_with_encoding(struct magic_set *ms, cons goto done; } - if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) { + if (ulen > 0 && (ms->flags & MAGIC_NO_CHECK_SOFT) == 0) { /* Convert ubuf to UTF-8 and try text soft magic */ /* malloc size is a conservative overestimate; could be improved, or at least realloced after conversion. */ mlen = ulen * 6; - utf8_buf = emalloc(mlen); - + if ((utf8_buf = CAST(unsigned char *, emalloc(mlen))) == NULL) { + file_oomem(ms, mlen); + goto done; + } if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL) goto done; @@ -209,6 +211,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, cons case 0: if (file_printf(ms, ", ") == -1) goto done; + break; case -1: goto done; default: