New submission from CensoredUsername:

If a pickle frame ends at the end of a pickle._Unframer.readline() call then an 
UnpicklingError("pickle exhausted before end of frame") will unconditionally be 
raised due to a faulty check if the frame ended before the line ended.

It concerns this conditional in pickle._Unframer.readline, line 245 in 
pickle.py:

if data[-1] != b'\n':
    raise UnpicklingError(
        "pickle exhausted before end of frame")

This comparison will always evaluate to True even if data ends in a newline. 
This is caused by data being a bytes object, and such data[-1] will evaluate to 
10 in case of data ending in a newline. 10 != b'\n' will then always evaluate 
to True due to the type mismatch, and the UnpicklingError will be raised.

This error can be corrected by slicing an actual one character bytes object 
like:

if data[-1:] != b'\n':
    raise UnpicklingError(
        "pickle exhausted before end of frame")

Or by comparing against the numeric representation of b'\n':

if data[-1] != b'\n'[0]:
    raise UnpicklingError(
        "pickle exhausted before end of frame")

----------
messages: 232984
nosy: CensoredUsername
priority: normal
severity: normal
status: open
title: Unpickler failing with PicklingError at frame end on readline due to a 
broken comparison
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23094>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to