[mod_python] ValueError with Flash 8 FileReference.upload(url)

Jim Gallacher jpg at jgassociates.ca
Wed Apr 5 08:32:07 EDT 2006


I don't have time to look at this in any detail right now, but I agree 
that it looks malformed. The last part of post.dat really shoud be:

------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7\r\n
Content-Disposition: form-data; name="Upload"\r\n
\r\n
Submit Query\r\n
------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7


mod_python 3.2.8 should handle embedded \r\n or \r\r sequences in the 
file contents correctly. There is even a unit test for this. ;)

Jim


Graham Dumpleton wrote:
> I am coming to the conclusion that the file produced by Flash is  
> malformed.
> 
> Even if I were to get rid of the double \r\r sequences, replacing  them 
> with a
> single \r, you end up with no blank like after:
> 
>   Content-Disposition: form-data; name="Upload"
> 
> which means that:
> 
>   Submit Query
> 
> gets interpreted as a header and thus why it dies as there is no  colon 
> on that
> line.
> 
> Anyone got any better ideas?
> 
> Bedtime for me now.
> 
> Graham
> 
> On 05/04/2006, at 9:32 PM, Graham Dumpleton wrote:
> 
>>
>> On 05/04/2006, at 9:28 PM, Harold J. Ship wrote:
>>
>>> Ok, here's the output.
>>>
>>> ------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7
>>>
>>> Content-Disposition: form-data; name="Filename"
>>>
>>>
>>>
>>> sample.txt
>>>
>>> ------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7
>>>
>>> Content-Disposition: form-data; name="Filedata";  filename="sample.txt"
>>>
>>> Content-Type: application/octet-stream
>>>
>>>
>>>
>>> Start of Sample Text File Contents
>>>
>>> End of Sample Text File Contents
>>>
>>>
>>>
>>> ------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7
>>>
>>> Content-Disposition: form-data; name="Upload"
>>>
>>> Submit Query
>>>
>>> ------------KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7
>>
>>
>> I'm not an expert on FieldStorage as I stayed out of all the  
>> discussions on
>> it when it was being improved. I am also not up on what the content  type
>> application/x-www-form-urlencoded is all about. All the same, I'll  share
>> what I found so far in case it helps someone else.
>>
>> First off, I don't get an error, but I don't believe I get correct  
>> results either.
>> To test, what I did was create a handler containing:
>>
>> from mod_python import apache, util
>>
>> def handler(req):
>>
>>     apache.log_error('headers_in=%s'%req.headers_in)
>>
>>     req.content_type = 'text/plain'
>>
>>     form = util.FieldStorage(req)
>>
>>     for field in form.list:
>>         apache.log_error('name=%s' % `field.name`)
>>         apache.log_error('value=%s' % `field.value`)
>>
>>     req.write('done')
>>
>>     return apache.OK
>>
>>
>> I then used "ab" to post your file to a URL mapping to that handler.
>>
>>   ab -p post.dat -T 'multipart/form-data; boundary=---------- 
>> KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7^M' http://localhost:8082/testing/ 
>> upload-1/dummy
>>
>> Note that that is actually a real \r (CR) where ^M is shown in the  
>> boundary.
>> Without that it wouldn't work. I am not sure though whether that is  
>> simply due
>> to CR LF weirdness in way file was created and then how it is being  
>> interpreted
>> by "ab" on Mac OS X when given to it as input.
>>
>> Anyway, result of that is:
>>
>> [Wed Apr 05 21:26:24 2006] [error] headers_in={'Content-type':  
>> 'multipart/form-data; boundary=---------- 
>> KM7GI3gL6cH2gL6gL6cH2gL6cH2KM7\r', 'Content-length': '498',  'Accept': 
>> '*/*', 'Host': 'localhost:8082', 'User-Agent':  'ApacheBench/1.3d'}
>> [Wed Apr 05 21:26:24 2006] [error] [client 127.0.0.1] PythonHandler  
>> upload: Traceback (most recent call last):
>> [Wed Apr 05 21:26:24 2006] [error] [client 127.0.0.1] PythonHandler  
>> upload:   File "/System/Library/Frameworks/Python.framework/ 
>> Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py",  line 
>> 308, in HandlerDispatch\n    result = object(req)
>> [Wed Apr 05 21:26:24 2006] [error] [client 127.0.0.1] PythonHandler  
>> upload:   File "/Users/grahamd/Workspaces/testing/upload-1/ 
>> upload.py", line 9, in handler\n    form = util.FieldStorage(req)
>> [Wed Apr 05 21:26:24 2006] [error] [client 127.0.0.1] PythonHandler  
>> upload:   File "/System/Library/Frameworks/Python.framework/ 
>> Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line  
>> 180, in __init__\n    h, v = line.split(":", 1)
>> [Wed Apr 05 21:26:24 2006] [error] [client 127.0.0.1] PythonHandler  
>> upload: ValueError: unpack list of wrong size
>>
>> Thus, have duplicated it.
>>
>> Note that this may possibly be something to do with strangeness in  
>> line endings.
>> First their was the issue above with CR, but there are other  nasties 
>> in input with
>> CR LF. See following "od" dump.
>>
>> 0000000    -   -   -   -   -   -   -   -   -   -   -   -   K   M    7   G
>> 0000020    I   3   g   L   6   c   H   2   g   L   6   g   L   6    c   H
>> 0000040    2   g   L   6   c   H   2   K   M   7  \r  \r  \n   C    o   n
>> 0000060    t   e   n   t   -   D   i   s   p   o   s   i   t   i    o   n
>> 0000100    :       f   o   r   m   -   d   a   t   a   ;       n    a   m
>> 0000120    e   =   "   F   i   l   e   n   a   m   e   "  \r  \r   \n  \r
>> 0000140   \r  \n   s   a   m   p   l   e   .   t   x   t  \r  \r   \n   -
>> 0000160    -   -   -   -   -   -   -   -   -   -   -   K   M   7    G   I
>> 0000200    3   g   L   6   c   H   2   g   L   6   g   L   6   c    H   2
>> 0000220    g   L   6   c   H   2   K   M   7  \r  \r  \n   C   o    n   t
>> 0000240    e   n   t   -   D   i   s   p   o   s   i   t   i   o    n   :
>> 0000260        f   o   r   m   -   d   a   t   a   ;       n   a    m   e
>> 0000300    =   "   F   i   l   e   d   a   t   a   "   ;       f    i   l
>> 0000320    e   n   a   m   e   =   "   s   a   m   p   l   e   .    t   x
>> 0000340    t   "  \r  \r  \n   C   o   n   t   e   n   t   -   T    y   p
>> 0000360    e   :       a   p   p   l   i   c   a   t   i   o    n   /   o
>> 0000400    c   t   e   t   -   s   t   r   e   a   m  \r  \r  \n   \r  \r
>> 0000420   \n   S   t   a   r   t       o   f       S   a   m   p    l   e
>> 0000440        T   e   x   t       F   i   l   e       C   o   n    t   e
>> 0000460    n   t   s  \r  \r  \n   E   n   d       o   f       S    a   m
>> 0000500    p   l   e       T   e   x   t       F   i   l   e        C   o
>> 0000520    n   t   e   n   t   s  \r  \r  \n  \r  \r  \n   -   -    -   -
>> 0000540    -   -   -   -   -   -   -   -   K   M   7   G   I   3    g   L
>> 0000560    6   c   H   2   g   L   6   g   L   6   c   H   2   g    L   6
>> 0000600    c   H   2   K   M   7  \r  \r  \n   C   o   n   t   e    n   t
>> 0000620    -   D   i   s   p   o   s   i   t   i   o   n   :        f   o
>> 0000640    r   m   -   d   a   t   a   ;       n   a   m   e   =    "   U
>> 0000660    p   l   o   a   d   "  \r  \r  \n   S   u   b   m   i   t
>> 0000700    Q   u   e   r   y  \r  \r  \n   -   -   -   -   -   -    -   -
>> 0000720    -   -   -   -   K   M   7   G   I   3   g   L   6   c    H   2
>> 0000740    g   L   6   g   L   6   c   H   2   g   L   6   c   H    2   K
>> 0000760    M   7
>> 0000762
>>
>> See the "\r  \r  \n  \r  \r  \n" sequences.
>>
>> Not sure that I'll have much more time to play with this tonight,  so 
>> posting this
>> progress in case someone else wants to pick up and continue.
>>
>> Graham
>>
>>
>>
>>
>>
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
> 



More information about the Mod_python mailing list