[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

aCaB acab at clamav.net
Sun Apr 4 01:19:59 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit c5bfb52e1a807270dc868e89a3b227626bbdf3fe
Author: aCaB <acab at clamav.net>
Date:   Sat Feb 13 02:59:28 2010 +0100

    purge message.c binhex parser

diff --git a/ChangeLog b/ChangeLog
index 02884f1..5947b3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Feb 13 02:55:55 CET 2010 (acab)
+-----------------------------------
+ * libclamav: refactor binhex processor with one pass decoder (bb#1236)
+
 Fri Feb 12 15:51:19 CET 2010 (tk)
 ---------------------------------
  * libclamav: add cl_countsigs() (bb#1473)
diff --git a/libclamav/message.c b/libclamav/message.c
index 659d374..d8e5b1a 100644
--- a/libclamav/message.c
+++ b/libclamav/message.c
@@ -1173,300 +1173,6 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
 
 	cli_dbgmsg("messageExport: numberOfEncTypes == %d\n", m->numberOfEncTypes);
 
-	if((t_line = binhexBegin(m)) != NULL) {
-		unsigned char byte;
-		unsigned long newlen = 0L, len, dataforklen, resourceforklen, l;
-		unsigned char *data;
-		char *ptr;
-		int bytenumber;
-		blob *tmp;
-
-		/*
-		 * HQX conversion table - illegal chars are 0xff
-		 */
-		const unsigned char hqxtbl[] = {
-			     /*   00   01   02   03   04   05   06   07   08   09   0a   0b   0c   0d   0e   0f */
-		/* 00-0f */	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-		/* 10-1f */	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-		/* 20-2f */	0xff,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0xff,0xff,
-		/* 30-3f */	0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0xff,0x14,0x15,0xff,0xff,0xff,0xff,0xff,0xff,
-		/* 40-4f */	0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0xff,
-		/* 50-5f */	0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0xff,0x2c,0x2d,0x2e,0x2f,0xff,0xff,0xff,0xff,
-		/* 60-6f */	0x30,0x31,0x32,0x33,0x34,0x35,0x36,0xff,0x37,0x38,0x39,0x3a,0x3b,0x3c,0xff,0xff,
-		/* 70-7f */	0x3d,0x3e,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
-		};
-
-		cli_dbgmsg("messageExport: decode binhex\n");
-		/*
-		 * Decode BinHex4. First create a temporary blob which contains
-		 * the encoded message. Then decode that blob to the target
-		 * blob, free the temporary blob and return the target one
-		 *
-		 * FIXME: EICAR isn't detected: should create 3 files in fork
-		 *	format: .info, .data and .rsrc. This is needed for
-		 *	position dependant detection such as EICAR
-		 *
-		 * See RFC1741
-		 */
-		while(((t_line = t_line->t_next) != NULL) &&
-		      (t_line->t_line == NULL))
-			;
-
-		if(!t_line) {
-			cli_warnmsg("No binhex data to parse\n");
-			(*destroy)(ret);
-			return NULL;
-		}
-
-		tmp = textToBlob(t_line, NULL,
-			((m->numberOfEncTypes == 1) && (m->encodingTypes[0] == BINHEX)) ? destroy_text : 0);
-
-		if(tmp == NULL) {
-			/*
-			 * FIXME: We've probably run out of memory during the
-			 * text to blob.
-			 */
-			cli_warnmsg("Couldn't start binhex parser\n");
-			(*destroy)(ret);
-			return NULL;
-		}
-
-		data = blobGetData(tmp);
-
-		if(data == NULL) {
-			cli_warnmsg("Couldn't locate the binhex message that was claimed to be there\n");
-			blobDestroy(tmp);
-			(*destroy)(ret);
-			return NULL;
-		}
-		len = blobGetDataSize(tmp);
-
-		if(data[0] == ':') {
-			unsigned char *uptr;
-			/* 7 bit (ala RFC1741) */
-
-			/*
-			 * FIXME: this is dirty code, modification of the
-			 * contents of a member of the blob object should be
-			 * done through blob.c
-			 *
-			 * Convert 7 bit data into 8 bit
-			 */
-			cli_dbgmsg("decode HQX7 message (%lu bytes)\n", len);
-
-			uptr = cli_malloc(len);
-			if(uptr == NULL) {
-				blobDestroy(tmp);
-				(*destroy)(ret);
-				return NULL;
-			}
-			memcpy(uptr, data, len);
-			bytenumber = 0;
-
-			/*
-			 * uptr now contains the encoded (7bit) data - len bytes long
-			 * data will contain the unencoded (8bit) data
-			 */
-			for(l = 1; l < len; l++) {
-				unsigned char c = uptr[l];
-
-				if(c == ':')
-					break;
-
-				if((c == '\n') || (c == '\r'))
-					continue;
-
-				if((c < 0x20) || (c > 0x7f) || (hqxtbl[c] == 0xff)) {
-					cli_dbgmsg("Invalid HQX7 character '%c' (0x%02x)\n", c, c);
-					break;
-				}
-				c = hqxtbl[c];
-				assert(c <= 63);
-
-				/*
-				 * These masks probably aren't needed, but
-				 * they're here to verify the code is correct
-				 */
-				switch(bytenumber) {
-					case 0:
-						data[newlen] = (c << 2) & 0xFC;
-						bytenumber = 1;
-						break;
-					case 1:
-						data[newlen++] |= (c >> 4) & 0x3;
-						data[newlen] = (c << 4) & 0xF0;
-						bytenumber = 2;
-						break;
-					case 2:
-						data[newlen++] |= (c >> 2) & 0xF;
-						data[newlen] = (c << 6) & 0xC0;
-						bytenumber = 3;
-						break;
-					case 3:
-						data[newlen++] |= c & 0x3F;
-						bytenumber = 0;
-						break;
-				}
-			}
-
-			cli_dbgmsg("decoded HQX7 message (now %lu bytes)\n", newlen);
-
-			/*
-			 * Throw away the old encoded (7bit) data
-			 * data now points to the encoded (8bit) data - newlen bytes
-			 *
-			 * The data array may contain repetitive characters
-			 */
-			free(uptr);
-		} else {
-			cli_warnmsg("HQX8 messages not yet supported, extraction may fail - if you believe this file contains a virus, submit it to www.clamav.net\n");
-			newlen = len;
-		}
-
-		/*
-		 * Uncompress repetitive characters
-		 */
-		if(memchr(data, 0x90, newlen)) {
-			blob *u = blobCreate();	/* uncompressed data */
-
-			if(u == NULL) {
-				(*destroy)(ret);
-				blobDestroy(tmp);
-				return NULL;
-			}
-			/*
-			 * Includes compression
-			 */
-			for(l = 0L; l < newlen; l++) {
-				unsigned char c = data[l];
-
-				/*
-				 * TODO: handle the case where the first byte
-				 * is 0x90
-				 */
-				blobAddData(u, &c, 1);
-
-				if((l < (newlen - 1L)) && (data[l + 1] == 0x90)) {
-					int count;
-
-					l += 2;
-					count = data[l];
-
-					if(count == 0) {
-						c = 0x90;
-						blobAddData(u, &c, 1);
-					} else {
-#ifdef	CL_DEBUG
-						cli_dbgmsg("uncompress HQX7 at 0x%06lu: %d repetitive bytes\n", l, count);
-#endif
-						blobGrow(u, count);
-						while(--count > 0)
-							blobAddData(u, &c, 1);
-					}
-				}
-			}
-			blobDestroy(tmp);
-			tmp = u;
-			data = blobGetData(tmp);
-			len = blobGetDataSize(tmp);
-			cli_dbgmsg("Uncompressed %lu bytes to %lu\n", newlen, len);
-		} else {
-			len = newlen;
-			cli_dbgmsg("HQX7 message (%lu bytes) is not compressed\n",
-				len);
-		}
-		if(len == 0) {
-			cli_dbgmsg("Discarding empty binHex attachment\n");
-			(*destroy)(ret);
-			blobDestroy(tmp);
-			return NULL;
-		}
-
-		/*
-		 * The blob tmp now contains the uncompressed data
-		 * of len bytes, i.e. the repetitive bytes have been removed
-		 */
-
-		/*
-		 * Parse the header
-		 *
-		 * TODO: set filename argument in message as well
-		 */
-		byte = data[0];
-		if(byte >= len) {
-			(*destroy)(ret);
-			blobDestroy(tmp);
-			return NULL;
-		}
-		filename = cli_malloc(byte + 1);
-		if(filename == NULL) {
-			(*destroy)(ret);
-			blobDestroy(tmp);
-			return NULL;
-		}
-		memcpy(filename, &data[1], byte);
-		filename[byte] = '\0';
-		(*setFilename)(ret, dir, filename);
-		/*ptr = cli_malloc(strlen(filename) + 6);*/
-		ptr = cli_malloc(byte + 6);
-		if(ptr) {
-			sprintf(ptr, "name=%s", filename);
-			messageAddArgument(m, ptr);
-			free(ptr);
-		}
-
-		/*
-		 * skip over length, filename, version, type, creator and flags
-		 */
-		byte = 1 + byte + 1 + 4 + 4 + 2;
-
-		/*
-		 * Set len to be the data fork length
-		 */
-		dataforklen = ((data[byte] << 24) & 0xFF000000) |
-			((data[byte + 1] << 16) & 0xFF0000) |
-			((data[byte + 2] << 8) & 0xFF00) |
-			(data[byte + 3] & 0xFF);
-
-		resourceforklen = ((data[byte + 4] << 24) & 0xFF000000) |
-			((data[byte + 5] << 16) & 0xFF0000) |
-			((data[byte + 6] << 8) & 0xFF00) |
-			(data[byte + 7] & 0xFF);
-
-		cli_dbgmsg("Filename = '%s', data fork length = %lu, resource fork length = %lu bytes\n",
-			filename, dataforklen, resourceforklen);
-
-		free((char *)filename);
-
-		/*
-		 * Skip over data fork length, resource fork length and CRC
-		 */
-		byte += 10;
-
-		l = blobGetDataSize(tmp) - byte;
-
-		if(l < dataforklen) {
-			cli_dbgmsg("Corrupt BinHex file, claims it is %lu bytes long in a message of %lu bytes\n",
-				dataforklen, l);
-			dataforklen = l;
-		}
-		if(setCTX && m->ctx)
-			(*setCTX)(ret, m->ctx);
-
-		(*addData)(ret, &data[byte], dataforklen);
-
-		blobDestroy(tmp);
-
-		if(destroy_text)
-			m->binhex = NULL;
-
-		if((m->numberOfEncTypes == 0) ||
-		   ((m->numberOfEncTypes == 1) && (m->encodingTypes[0] == BINHEX))) {
-			cli_dbgmsg("Finished exporting binhex file\n");
-			return ret;
-		}
-	}
-
 	if(m->numberOfEncTypes == 0) {
 		/*
 		 * Fast copy

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list