Issue1942

Title zeroconf crashes hg serve if web.description contains non-ASCII chars
Priority bug Status testing
Superseder Nosy List brendan, danchr, hstuart, mg, piranha, pmezard, tonfa, wbruna
Assigned To piranha Topics

Created on 2009-12-09.16:00:51 by wbruna, last changed 2010-02-06.17:00:50 by brendan.

Messages
msg11626 (view) Author: brendan Date: 2010-02-06.17:00:50
See http://hg.intevation.org/mercurial/crew/rev/b8e3aeb7542c (zeroconf: do not try to encode encoded strings (issue1942))
msg11625 (view) Author: hstuart Date: 2010-02-06.16:41:24
We got bitten by this at the sprint so I went ahead and fixed it. In crew as
b8e3aeb7542c.
msg11191 (view) Author: piranha Date: 2009-12-09.20:53:59
I'll work on patch for this
msg11190 (view) Author: piranha Date: 2009-12-09.20:19:55
Zeroconf is pretty much unmaintained now and I even have a fork of it at
http://hg.piranha.org.ua/python-zeroconf/. So I think it's ok to modify it,
especially given that it was already changed previously.
msg11189 (view) Author: mg Date: 2009-12-09.18:56:48
Yeah, that's bound to go wrong -- the code in question does:

  elif isinstance(value, str):
      suffix = value.encode('utf-8')

So value is a (byte) string and the code tries to *encode* it. That's
effectively the same as doing

   unicode(value).encode('utf-8')

which in turn is the same as

   value.decode('ASCII').encode('utf-8')

since the default codec is still ASCII. I think this looks like a
mistake in Zeroconf -- it could have made sense if it tried to *decode*
the string from a UTF-8 byte string to a Unicode object.

I don't really know anything about zeroconf, though. If it does not
support non-ASCII characters at all, then we can solve the problem on
our end by stripping them. If it does support, say, UTF-8 encoded
strings, then this looks like a bug in Zeroconf.
msg11187 (view) Author: wbruna Date: 2009-12-09.17:55:48
I have:

LANG=pt_BR.UTF-8
LANGUAGE=pt_BR:en
LC_ALL=en_US.UTF-8

I changed LANGUAGE to C before running the test; it doesn't seem to matter.

A description with ISO-8859-1 accented chars triggers the error too.
msg11186 (view) Author: tonfa Date: 2009-12-09.17:44:57
What is your locale ?
msg11185 (view) Author: wbruna Date: 2009-12-09.16:00:51
$ hg init t
$ cd t
$ hg --config 'extensions.hgext.zeroconf=' --config
'web.description=repositório' serve
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Mercurial Distributed SCM (version 1.4.1+4-8bce1e0d2801)
** Extensions loaded: acl, bookmarks, churn, color, convert, extdiff, fetch,
graphlog, hgcia, hgk, mq, notify, parentrevspec, patchbomb, purge, record,
rebase, share, transplant, relink, hgsubversion, hgeol, qup, rpc, zeroconf
Traceback (most recent call last):
  File "/home/wbruna/bin/hg", line 27, in <module>
    mercurial.dispatch.run()
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 16, in run
    sys.exit(dispatch(sys.argv[1:]))
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 30, in dispatch
    return _runcatch(u, args)
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 46, in _runcatch
    return _dispatch(ui, args)
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 454, in _dispatch
    return runcommand(lui, repo, cmd, fullargs, ui, options, d)
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 324, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 505, in
_runcommand
    return checkargs()
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 459, in checkargs
    return cmdfunc()
  File "/home/wbruna/hg/hg/inst_/mercurial/dispatch.py", line 453, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/home/wbruna/hg/hg/inst_/mercurial/util.py", line 386, in check
    return func(*args, **kwargs)
  File "/home/wbruna/hg/hg/inst_/mercurial/commands.py", line 2830, in serve
    cmdutil.service(opts, initfn=service.init, runfn=service.run)
  File "/home/wbruna/hg/hg/inst_/mercurial/cmdutil.py", line 577, in service
    initfn()
  File "/home/wbruna/hg/hg/inst_/mercurial/commands.py", line 2800, in init
    self.httpd = server.create_server(baseui, repo)
  File "mercurial/hgweb/server.py", line 295, in create_server
  File "mercurial/hgweb/server.py", line 256, in __init__
  File "mercurial/hgweb/server.py", line 251, in make_handler
  File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 106, in __init__

  File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 87, in publish

  File "hgext/zeroconf/Zeroconf.py", line 1052, in __init__
  File "hgext/zeroconf/Zeroconf.py", line 1065, in setProperties
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7:
ordinal not in range(128)

Ctrl-c doesn't kill the hg process afterwards; I had to use kill -9.
History
Date User Action Args
2010-02-06 17:00:50brendansetnosy: + brendan
messages: + msg11626
2010-02-06 16:41:24hstuartsetstatus: chatting -> testing
nosy: + hstuart
messages: + msg11625
2009-12-10 20:42:12pmezardsetnosy: + pmezard
2009-12-09 20:53:59piranhasetnosy: tonfa, mg, wbruna, piranha, danchr
messages: + msg11191
assignedto: piranha
2009-12-09 20:19:56piranhasetnosy: tonfa, mg, wbruna, piranha, danchr
messages: + msg11190
2009-12-09 18:56:48mgsetnosy: + mg
messages: + msg11189
2009-12-09 17:55:48wbrunasetmessages: + msg11187
2009-12-09 17:44:57tonfasetstatus: unread -> chatting
nosy: + tonfa
messages: + msg11186
2009-12-09 16:41:43danchrsetnosy: + danchr
2009-12-09 16:40:39piranhasetnosy: + piranha
2009-12-09 16:00:51wbrunacreate