Edgewall Software

Opened 9 years ago

Last modified 9 years ago

#12017 closed defect

UnicodeDecodeError in log file — at Version 1

Reported by: Ryan J Ollos Owned by: Dirk Stöcker
Priority: normal Milestone: 1.0.7
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Jun Omae)

Running the latest SpamFilter plugin [13942], I find the following errors in the log:

2015-04-01 23:15:33,851 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/main.py", line 513, in _dispatch_request
    dispatcher.dispatch(req)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/main.py", line 187, in dispatch
    self._pre_process_request(req, chosen_handler)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/main.py", line 334, in _pre_process_request
    chosen_handler = filter_.pre_process_request(req, chosen_handler)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/TracSpamFilter-1.0.6dev_r13942-py2.6.egg/tracspamfilter/captcha/api.py", line 167, in pre_process_request
    elif req.args.get('captcha_response', "") == exp:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/api.py", line 355, in __getattr__
    value = self.callbacks[name](self)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/api.py", line 338, in <lambda>
    'args': lambda req: arg_list_to_args(req.arg_list),
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/api.py", line 355, in __getattr__
    value = self.callbacks[name](self)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/api.py", line 704, in _parse_arg_list
    value = unicode(value.value, 'utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 37: invalid start byte

SpamFilter plugin should at least trap the UnicodeDecodeErrors so that tracebacks don't result in the log.

Change History (1)

comment:1 by Jun Omae, 9 years ago

Component: plugin/spamfiltergeneral
Description: modified (diff)

No. That is not a SpamFilter issue. We can raise the same error on any components, e.g. /wiki?name=%FF, /query?name=%FF.

  • trac/web/api.py

    diff --git a/trac/web/api.py b/trac/web/api.py
    index 3944020..0e62804 100644
    a b class Request(object):  
    702702            self.environ['QUERY_STRING'] = qs_on_post
    703703
    704704        args = []
    705         for value in fs.list or ():
    706             name = value.name
    707             if not value.filename:
    708                 value = unicode(value.value, 'utf-8')
    709             args.append((name, value))
     705        try:
     706            for value in fs.list or ():
     707                name = value.name
     708                if not value.filename:
     709                    value = unicode(value.value, 'utf-8')
     710                args.append((name, value))
     711        except UnicodeDecodeError, e:
     712            raise HTTPBadRequest(_("Invalid encoding in form data: %(msg)s",
     713                                   msg=exception_to_unicode(e)))
    710714        return args
    711715
    712716    def _parse_cookies(self):

After the patch, the following without traceback would be logged by invalid enoding.

2015-04-13 13:35:57,989 Trac[main] WARNING: [192.168.11.24] HTTPBadRequest: 400 Bad Request (Invalid encoding in form data: UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: unexpected code byte)

I noticed that /wiki?%FF=xxxx doesn't lead the same error. I think we should decode the names to unicode with utf-8 encoding.

-            name = value.name
+            name = unicode(value.name, 'utf-8')
Last edited 9 years ago by Jun Omae (previous) (diff)
Note: See TracTickets for help on using tickets.