Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 86303) +++ Python/pythonrun.c (working copy) @@ -2044,9 +2044,22 @@ errtext = Py_None; Py_INCREF(Py_None); } else { + PyObject *s; errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), "replace"); + /* Fix offset */ + s = PyUnicode_DecodeUTF8(err->text, err->offset, "replace"); + if (s == NULL) { + PyErr_Clear(); + /* XXX: We can probably do better than that. */ + err->offset = 0; + } + else { + err->offset = PyUnicode_GET_SIZE(s); + Py_DECREF(s); + } } + if (err->filename != NULL) filename = PyUnicode_DecodeFSDefault(err->filename); else {