You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pickle is unable to encode unicode surrogates #52630
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-04-13.11:10:22.602>created_at=<Date2010-04-13.00:39:55.090>labels= ['library']
title='pickle is unable to encode unicode surrogates'updated_at=<Date2010-04-13.11:10:22.601>user='https://github.com/vstinner'
Python3 uses unicode surrogates to store undecodable filenames. Eg. the filename b"abc\xff.py" is encoded as "abc\xdcff.py" if the file system encoding is ASCII. Pickle is unable to store them:
./python -c 'import pickle; pickle.dumps("abc\udcff")'
(...)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 20: surrogates not allowed
This is a limitation of pickle (in the binary mode): Python accepts to store any unicode character, but pickle doesn't.
Using "surrogatepass" error handler should be enough to fix this issue.
Related issue: bpo-3672 (Reject surrogates in utf-8 codec) -> r72208 creates "surrogatepass" error handler.
I found this bug indirectly: test_logging failed on a SocketHandler if LogRecord.pathname contains a surrogate character. SocketHandler uses pickle to serialize the record.
Both pickle and marshal will need to use the new error handler in order to stay compatible with Python 3.0 (and 2.x) and also to enable creating Unicode literals that include lone surrogates.
Both pickle and marshal will need to use the new error handler
in order to stay compatible with Python 3.0 (and 2.x)
and also to enable creating Unicode literals that include
lone surrogates.
Attached patch fixes pickle. Marshal does already use surrogatepass since Martin's commit r72208 (Issue bpo-3672).
> Both pickle and marshal will need to use the new error handler
> in order to stay compatible with Python 3.0 (and 2.x)
> and also to enable creating Unicode literals that include
> lone surrogates.
Attached patch fixes pickle. Marshal does already use surrogatepass since Martin's commit r72208 (Issue bpo-3672).
Activity
vstinner commentedon Apr 13, 2010
Python3 uses unicode surrogates to store undecodable filenames. Eg. the filename b"abc\xff.py" is encoded as "abc\xdcff.py" if the file system encoding is ASCII. Pickle is unable to store them:
./python -c 'import pickle; pickle.dumps("abc\udcff")'
(...)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 20: surrogates not allowed
This is a limitation of pickle (in the binary mode): Python accepts to store any unicode character, but pickle doesn't.
Using "surrogatepass" error handler should be enough to fix this issue.
Related issue: bpo-3672 (Reject surrogates in utf-8 codec) -> r72208 creates "surrogatepass" error handler.
vstinner commentedon Apr 13, 2010
I found this bug indirectly: test_logging failed on a SocketHandler if LogRecord.pathname contains a surrogate character. SocketHandler uses pickle to serialize the record.
malemburg commentedon Apr 13, 2010
Both pickle and marshal will need to use the new error handler in order to stay compatible with Python 3.0 (and 2.x) and also to enable creating Unicode literals that include lone surrogates.
vstinner commentedon Apr 13, 2010
Attached patch fixes pickle. Marshal does already use surrogatepass since Martin's commit r72208 (Issue bpo-3672).
malemburg commentedon Apr 13, 2010
STINNER Victor wrote:
Looks good !
Thanks.
vstinner commentedon Apr 13, 2010
Commited: r80031 (py3k) and r80032 (3.1), fix also pickletools.