On 2004-02-12T10:24:08+0100, Biot Olivier wrote:
> Wait a minute: this method should be made available to all dissectors!

Take it. It should be reasonable generic (but maybe needs another
name):

/* 
 * Uncompresses a zlib compressed packet inside a tvb 
 * tvb*: the tvb; not touched in any way
 * offset: offset inside tvb
 * comprlen: length of compressed data
 * Returns a new uncompressed tvbuffer if uncompression succeeded 
 * or NULL if uncompression failed (or HAVE_LIBZ is not defined)
 */

tvbuff_t* uncompress_packet(tvbuff_t *tvb, int offset, int comprlen);

The only problems arise because there is no easy way to determine
the size of the uncompressed buffer. Currently the code takes a
(conservative?) guess that the uncompressed buffer is 9 times
larger than the compressed one. Uncompress failes if this guess
was wrong.

An alternative would be the use of inflate() and iterative memory
allocation.

Attached is a diff to make MSVC happier.

Kendy

-- 

Index: packet-slsk.c
===================================================================
RCS file: /cvsroot/ethereal/packet-slsk.c,v
retrieving revision 1.1
diff -u -r1.1 packet-slsk.c
--- packet-slsk.c       11 Feb 2004 20:23:19 -0000      1.1
+++ packet-slsk.c       12 Feb 2004 12:35:17 -0000
@@ -304,19 +304,34 @@
        *             or NULL if uncompression failed
        */
        
-       char compr[comprlen];
        int i = 0;
-       long uncomprlen = (comprlen*10);
-       char uncompr[uncomprlen];
        int err = 0;
+       long uncomprlen = (comprlen*10);
+       guint8 * compr;
+       guint8 * uncompr;
        tvbuff_t *uncompr_tvb;
 
+       compr = g_malloc(comprlen);
+       if (!compr){
+               return NULL;
+       }
+       uncompr = g_malloc(uncomprlen);
+       if (!uncompr){
+               g_free(compr);
+               return NULL;
+       }
+
        while (i < comprlen) { compr[i] = tvb_get_guint8(tvb, offset+i); i++;}
 
        err = uncompress((Bytef *)uncompr, &uncomprlen, (Bytef *)compr, comprlen);
-       if (err != 0) return NULL;
+       g_free(compr);
+       if (err != 0) {
+               g_free(uncompr);
+               return NULL;
+       }
        
        uncompr_tvb =  tvb_new_real_data((guint8*) uncompr, uncomprlen, uncomprlen);
+       g_free(uncompr);
        return uncompr_tvb;
 }
 #else

Attachment: pgp00000.pgp
Description: PGP signature

_______________________________________________
Ethereal-dev mailing list
[EMAIL PROTECTED]
http://www.ethereal.com/mailman/listinfo/ethereal-dev

Reply via email to