fix TextIOWrapper.read() when the buffer is not readable #5628
diff --git a/Modules/_textio.c b/Modules/_textio.c
index dbfc8ae..cc229a8 100644
--- a/Modules/_textio.c
+++ b/Modules/_textio.c
@@ -1348,6 +1348,11 @@
 
     CHECK_CLOSED(self);
 
+    if (self->decoder == NULL) {
+        PyErr_SetString(PyExc_IOError, "not readable");
+        return NULL;
+    }
+
     if (_TextIOWrapper_writeflush(self) < 0)
         return NULL;