Edgewall Software
Modify

Opened 8 years ago

Closed 6 years ago

#9880 closed defect (fixed)

ValueError: Invalid boundary in multipart form: ''

Reported by: tg@… Owned by: Christian Boos
Priority: normal Milestone: 0.12.5
Component: attachment Version: 0.12
Severity: normal Keywords: upload multipart
Cc:
Release Notes:

Fix upload of files which are categorized as having a multipart/related content type (e.g. *.mht files).

API Changes:

Description

How to Reproduce

While doing a POST operation on /attachment/wiki/RESTfulAPI/, Trac issued an internal error.

(please provide additional details here)

Request parameters:

{'action': u'new',
 'description': u'JustDrive MAPP RESTFUL API Reference',
 'id': u'RESTfulAPI',
 'realm': u'wiki'}

User agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0C)

System Information

Trac 0.12
Babel 0.9.5
Docutils 0.7
FullBlog 0.1.1
Genshi 0.6
Pygments 1.3.1
pysqlite 2.4.1
Python 2.6.6 (r266:84292, Sep 24 2010, 01:08:42)
[GCC 4.2.1 20070719 [FreeBSD]]
pytz 2010l
setuptools 0.6c11
SilverCity 0.9.7
SQLite 3.7.2
Subversion 1.6.13 (r1002816)
jQuery 1.4.2

Enabled Plugins

TracAccountManager 0.2.1dev
TracFullBlogPlugin 0.1.1

Python Traceback

Traceback (most recent call last):
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/main.py", line 511, in _dispatch_request
    dispatcher.dispatch(req)
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/main.py", line 193, in dispatch
    if handler.match_request(req):
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/attachment.py", line 408, in match_request
    req.args['realm'] = realm
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/api.py", line 212, in __getattr__
    value = self.callbacks[name](self)
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/api.py", line 195, in <lambda>
    'args': lambda req: arg_list_to_args(req.arg_list),
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/api.py", line 212, in __getattr__
    value = self.callbacks[name](self)
  File "build/bdist.freebsd-8.1-RELEASE-p1-i386/egg/trac/web/api.py", line 560, in _parse_arg_list
    fs = cgi.FieldStorage(fp, environ=self.environ, keep_blank_values=True)
  File "/usr/local/lib/python2.6/cgi.py", line 508, in __init__
    self.read_multi(environ, keep_blank_values, strict_parsing)
  File "/usr/local/lib/python2.6/cgi.py", line 637, in read_multi
    environ, keep_blank_values, strict_parsing)
  File "/usr/local/lib/python2.6/cgi.py", line 508, in __init__
    self.read_multi(environ, keep_blank_values, strict_parsing)
  File "/usr/local/lib/python2.6/cgi.py", line 622, in read_multi
    raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,)
ValueError: Invalid boundary in multipart form: ''

Attachments (2)

trac_upload_mht_error.zip (396.8 KB ) - added by anonymous 6 years ago.
zip showing the issue
0001-web-handle-upload-of-a-file-having-itself-a-multipar.patch (1.6 KB ) - added by Christian Boos 6 years ago.
revert to reading a single part when multipart fails

Download all attachments as: .zip

Change History (19)

comment:1 Changed 8 years ago by Remy Blank

How come a POST is executed to the URL supposed to show the list of attachments for a resource? What operation were you doing? Uploading an attachment?

comment:2 Changed 8 years ago by Christian Boos

No, the URL is the correct one you get when trying to attach a file on a Wiki page, the parameters are in the form-data.

A few follow-up questions: Which size had the file you tried to attach? Any special character in the name of the file? Which browser did you use? Is the error reproducible? If yes, is this reproducible also with a different browser, or a different file?

comment:3 Changed 8 years ago by anonymous

I can reproduce it in any browser, I just upload a PDF document to the (any) TRAC WIKI Page.

comment:4 in reply to:  2 Changed 8 years ago by tg@…

Replying to cboos:

No, the URL is the correct one you get when trying to attach a file on a Wiki page, the parameters are in the form-data.

A few follow-up questions: Which size had the file you tried to attach? Any special character in the name of the file? Which browser did you use? Is the error reproducible? If yes, is this reproducible also with a different browser, or a different file?

Which size had the file you tried to attach? (FILESIZE: 33.1KB) Any special character in the name of the file? (FILENAME: JD-API-DOCS.pdf) Which browser did you use? (Started with FF 3.6.12, Chrome and IE have the same issue)

More notes: Its not the install because I can upload DOC files no issue. I uploaded the DOC version of this file and it went right up.

comment:5 Changed 8 years ago by Christian Boos

Do you have the problem with any PDF, or just this one? If possible, can you please try to attach it here?

comment:6 Changed 8 years ago by Thijs Triemstra

Keywords: needinfo added

comment:7 Changed 8 years ago by Christian Boos

Ping. Did you find a fix for this problem?

Without any feedback on comment:5, this ticket will be closed anyway…

comment:8 Changed 8 years ago by Christian Boos

Resolution: cantfix
Status: newclosed

No feedback, closing.

comment:9 Changed 7 years ago by anonymous

Resolution: cantfix
Status: closedreopened

I'm having the same problem when trying to attach a zip file. I was able to attach other zip files ok.

comment:10 in reply to:  9 Changed 7 years ago by Remy Blank

Replying to anonymous:

I'm having the same problem when trying to attach a zip file. I was able to attach other zip files ok.

That doesn't help us much :( We need more information to be able to reproduce the issue. Can you attach the zip file here, please?

comment:11 Changed 6 years ago by Christian Boos

Resolution: cantfix
Status: reopenedclosed

Still no appropriate feedback.

If anyone else experiences the same problem, please understand that we need a way to be able to reproduce the issue before fixing it (if it needs fixing and is not some bug or misconfiguration in the http server used, for example…).

comment:12 Changed 6 years ago by anonymous

Resolution: cantfix
Status: closedreopened

I am getting this error. We are still on 0.12.3. Planning on upgrading to 1.0 after the first of the year. I am trying to upload an .mht file. I will try and attach an mht. If that doesn't work, I will upload a zip of the same file. In my case, the zip works, but the mht does not.

Changed 6 years ago by anonymous

Attachment: trac_upload_mht_error.zip added

zip showing the issue

comment:13 Changed 6 years ago by Michael Schall <mike.schall@…>

Sorry, I was anonymous. Adding comment to get my name on this and hopefully emails back when the ticket is updated.

The mht file did fail to upload, so I uploaded the zip file instead.

Background: we use TRAC internally for our ticket system and would like to upload the results of PSR as part of our tickets. http://technet.microsoft.com/en-us/windows/problem-steps-recorder-overview.aspx

comment:14 Changed 6 years ago by Christian Boos

Keywords: needinfo removed
Milestone: next-stable-1.0.x

Thanks for the feedback, issue reproduced.

Looks like the Python FieldStorage has trouble with these sort of files, see python-issue:15564. No workaround is suggested there, besides renaming your file before upload.

comment:15 Changed 6 years ago by Christian Boos

The confusing thing about this error was that the "Content-Type" the code sees is not the one found in the .mht "header", but rather what is set up by the browser. For example, in Chrome:

------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="__FORM_TOKEN"

3788947f59945bf56df05625
------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="attachment"; filename="Problem.mht"
Content-Type: multipart/related


------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="description"

http://trac.edgewall.org/attachment/ticket/9880/trac_upload_mht_error.zip
------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="action"

new
------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="realm"

ticket
------WebKitFormBoundarySS6Q3DSdLiNQUC3t
Content-Disposition: form-data; name="id"

179
------WebKitFormBoundarySS6Q3DSdLiNQUC3t--

So here indeed the Content-Type is just multipart/related and the inner boundary ends up being ''. We should simply replace this content type with something more neutral when we can expect this inner boundary to be invalid.

Changed 6 years ago by Christian Boos

revert to reading a single part when multipart fails

comment:16 Changed 6 years ago by Christian Boos

Component: generalattachment
Keywords: upload multipart added
Milestone: next-stable-1.0.x0.12.5
Owner: set to Christian Boos
Status: reopenedassigned

Ok, changing the Content-Type on the fly proved to be impractical, but catching the error and adapting was easy enough. The patch is on 0.12-stable and I tested with Python 2.7.

comment:17 Changed 6 years ago by Christian Boos

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed the patch in r11498 and corresponding regression test in r11499, then ported to 1.0.1dev (r11501) and 1.1.1dev (r11503).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.