[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Untested patch to correctly decompress reassembled mess...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv20766/lib/mixminion

Modified Files:
	ClientMain.py ClientUtils.py 
Log Message:
Untested patch to correctly decompress reassembled messages when
reassembling on client side; to check for reassembly before opening an
output file; to give good errors for message ids that don't exist.
Should fix bugs 31,32,33.


Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -d -r1.173 -r1.174
--- ClientMain.py	23 Mar 2004 05:15:16 -0000	1.173
+++ ClientMain.py	24 Mar 2004 20:39:56 -0000	1.174
@@ -29,7 +29,8 @@
      previousMidnight
 from mixminion.Packet import encodeMailHeaders, ParseError, parseMBOXInfo, \
      parseReplyBlocks, parseSMTPInfo, parseTextEncodedMessages, \
-     parseTextReplyBlocks, ReplyBlock, parseMessageAndHeaders
+     parseTextReplyBlocks, ReplyBlock, parseMessageAndHeaders, \
+     CompressedDataTooLong
 
 from mixminion.ServerInfo import displayServerByRouting, ServerInfo
 
@@ -1962,12 +1963,12 @@
 """.strip()
 
 def reassemble(cmd, args):
-    options, args = getopt.getopt(args, "hvQf:D:Po:",
+    options, args = getopt.getopt(args, "hvQf:D:Po:F",
                                   ["help", "verbose", "quiet", "config=",
                                    'download-directory=','--purge',
-                                   '--output'])
+                                   '--output', '--force'])
     reassemble = 1
-    if cmd.endswith("purge-fragments"):
+    if cmd.endswith("purge-fragments") or cmd.endswith("purge-fragment"):
         reassemble = 0
     try:
         parser = CLIArgumentParser(options, wantConfig=1, wantLog=1,
@@ -1975,18 +1976,24 @@
     except UsageError, e:
         e.dump()
         print _REASSEMBLE_USAGE % { 'cmd' : cmd }
-        print """\
+        if reassemble:
+            print """\
   -P, --purge                Remove the message from the pool.
+  -F, --force:               Decode the message, even if it seems
+                             overcompressed.
   -o <file>, --output=<file> Write the message to a file instead of stdout
 """.strip()
         sys.exit(1)
     purge = not reassemble
     outfilename = None
+    force = 0
     for o,v in options:
         if o in ('-o', '--output'):
             outfilename = v
         elif o in ("-P", "--purge"):
             purge = 1
+        elif o ("-F", "--force"):
+            force = 1
 
     if not args:
         print "No message IDs provided."
@@ -1996,24 +2003,27 @@
     client = parser.client
 
     closeoutfile = 0
-    if reassemble:
-        out = sys.stdout
-        if outfilename not in ('-',None):
-            out = open(outfilename, 'wb')
-            closeoutfile = 1
-
+    out = None
     clientLock()
     try:
         removed = []
         for msgid in args:
             if reassemble:
-                msg = client.pool.getMessage(msgid)
+                try:
+                    msg = client.pool.getMessage(msgid, force=force)
+                except CompressedDataTooLong:
+                    raise UIError("Can't reassemble message %s: possible zlib bomb.")
+                if out == None:
+                    if outfilename in ('-',None):
+                        out = sys.stdout
+                    else:
+                        out = open(outfilename, 'wb')
+                        closeoutfile = 1
+                out.write(msg)
             if purge:
                 removed.append(msgid)
         client.pool.removeMessages(removed)
-        if reassemble:
-            out.write(msg)
     finally:
-        if reassemble and closeoutfile:
+        if closeoutfile:
             out.close()
         clientUnlock()

Index: ClientUtils.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientUtils.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ClientUtils.py	7 Mar 2004 06:31:46 -0000	1.25
+++ ClientUtils.py	24 Mar 2004 20:39:56 -0000	1.26
@@ -928,14 +928,28 @@
         pool.expireMessages(cutoff)
         self.cleanQueue()
 
-    def getMessage(self, msgid):
-        """Return the string value of the reassembled message with ID 'msgid',
-           or raise an error explaining why we can't."""
+    def getMessage(self, msgid, force=0):
+        """Return the string value of the (compressed) reassembled
+           message with ID 'msgid', or raise an error explaining why
+           we can't.
+
+           If 'force' is true, return the message even if it seems
+           overcompressed.  Otherwise raise a CompressedDataTooLong
+           exception.
+        """
         pool = self.__getPool()
         state = pool.getStateByMsgID(msgid)
-        msg = pool.getReadyMessage(state.messageid)
-        if msg is not None:
-            return msg
+        if state is not None:
+            msg = pool.getReadyMessage(state.messageid)
+            if msg is not None:
+                try:
+                    if force:
+                        maxSize = None
+                    else:
+                        maxSize = msg*20
+                    return mixminion.Packet.uncompressData(msg,maxSize)
+                except ParseError, e:
+                    raise UIError("Invalid message %s: %s"%(msgid,e))
 
         if state is None:
             raise UIError("No such message as '%s'" % msgid)