Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97249:c795f015ed36
Date: 2019-08-23 16:50 +0100
http://bitbucket.org/pypy/pypy/changeset/c795f015ed36/
Log: Check return value of decoder.getstate()
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -663,12 +663,15 @@
# To prepare for tell(), we need to snapshot a point in the file
# where the decoder's input buffer is empty.
w_state = space.call_method(self.w_decoder, "getstate")
+ if (not space.isinstance_w(w_state, space.w_tuple)
+ or space.len_w(w_state) != 2):
+ raise oefmt(space.w_TypeError, "illegal decoder state")
# Given this, we know there was a valid snapshot point
# len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
w_dec_buffer, w_dec_flags = space.unpackiterable(w_state, 2)
if not space.isinstance_w(w_dec_buffer, space.w_bytes):
- msg = "decoder getstate() should have returned a bytes " \
- "object not '%T'"
+ msg = ("illegal decoder state: the first value should be a "
+ "bytes object not '%T'")
raise oefmt(space.w_TypeError, msg, w_dec_buffer)
dec_buffer = space.bytes_w(w_dec_buffer)
dec_flags = space.int_w(w_dec_flags)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit